Skip to content

Commit 1d24188

Browse files
authored
Merge pull request #26 from MicrosoftCloudEssentials-LearningHub/front-door
Front door sample
2 parents 4a57059 + 57baa35 commit 1d24188

File tree

6 files changed

+241
-0
lines changed

6 files changed

+241
-0
lines changed

3_networking/front-door/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Terraform Template - Azure Front Door
2+
3+
Costa Rica
4+
5+
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
6+
[brown9804](https://github.com/brown9804)
7+
8+
Last updated: 2025-06-12
9+
10+
----------
11+
12+
> This template contains Terraform configurations to create and manage an Azure Front Door Standard/Premium profile, including frontend endpoint, backend pool, health probe, and routing rule.
13+
14+
> [!NOTE]
15+
> This Front Door configuration uses best practices for global HTTP/HTTPS load balancing and health monitoring.
16+
17+
<p align="center">
18+
<img width="700" alt="image" src="https://github.com/user-attachments/assets/2571f8a5-a5d3-4785-9b50-71275a31ab77">
19+
</p>
20+
21+
## File Descriptions
22+
23+
- **main.tf**: Contains the main configuration for creating the Azure Front Door profile and its associated resources.
24+
- **variables.tf**: Defines the input variables used in the Terraform configuration.
25+
- **terraform.tfvars**: Provides default values for the variables defined in `variables.tf`.
26+
- **outputs.tf**: Defines the outputs such as Front Door profile ID and frontend endpoint hostname.
27+
28+
## Variables
29+
30+
> Below is a list of variables used in this template, their expected values, types, and examples:
31+
32+
| Variable Name | Description | Type | Example Value |
33+
|---------------------- |--------------------------------------------------|--------|-----------------------------|
34+
| `subscription_id` | The Azure subscription ID | string | `"00000000-0000-0000-0000-000000000000"` |
35+
| `resource_group_name` | The name of the resource group | string | `"my-frontdoor-rg"` |
36+
| `location` | The Azure region to deploy resources | string | `"eastus"` |
37+
| `front_door_name` | The name of the Azure Front Door profile | string | `"myfrontdoorprofile"` |
38+
| `backend_host` | The backend host (FQDN or IP) for Front Door | string | `"mybackend.example.com"` |
39+
40+
## Usage
41+
42+
1. Clone the repository and navigate to the front-door directory.
43+
2. Update the `terraform.tfvars` file with your values.
44+
3. Initialize and apply the Terraform configuration:
45+
46+
```bash
47+
terraform init
48+
terraform plan
49+
terraform apply
50+
```
51+
52+
## Outputs
53+
54+
| Output Name | Description |
55+
|------------------------------|---------------------------------------------|
56+
| `front_door_id` | The ID of the Front Door profile |
57+
| `front_door_frontend_endpoint` | The frontend endpoint hostname of Front Door |
58+
59+
<div align="center">
60+
<h3 style="color: #4CAF50;">Total Visitors</h3>
61+
<img src="https://profile-counter.glitch.me/brown9804/count.svg" alt="Visitor Count" style="border: 2px solid #4CAF50; border-radius: 5px; padding: 5px;"/>
62+
</div>

3_networking/front-door/main.tf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# main.tf
2+
# Azure Front Door Standard/Premium configuration with required origin group and origin
3+
4+
resource "azurerm_resource_group" "fd" {
5+
name = var.resource_group_name
6+
location = var.location
7+
}
8+
9+
resource "azurerm_cdn_frontdoor_profile" "fd" {
10+
name = var.front_door_name
11+
resource_group_name = azurerm_resource_group.fd.name
12+
sku_name = "Standard_AzureFrontDoor"
13+
}
14+
15+
resource "azurerm_cdn_frontdoor_endpoint" "fd" {
16+
name = var.frontend_endpoint_name
17+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.fd.id
18+
}
19+
20+
resource "azurerm_cdn_frontdoor_origin_group" "fd" {
21+
name = "originGroup1"
22+
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.fd.id
23+
24+
health_probe {
25+
interval_in_seconds = 30
26+
path = var.health_probe_path
27+
protocol = var.health_probe_protocol
28+
request_type = "GET"
29+
}
30+
31+
load_balancing {
32+
sample_size = 4
33+
successful_samples_required = 3
34+
}
35+
}
36+
37+
resource "azurerm_cdn_frontdoor_origin" "fd" {
38+
name = "origin1"
39+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.fd.id
40+
host_name = var.backend_host
41+
http_port = 80
42+
https_port = 443
43+
enabled = true
44+
origin_host_header = var.backend_host
45+
priority = 1
46+
weight = 1000
47+
certificate_name_check_enabled = true
48+
}
49+
50+
resource "azurerm_cdn_frontdoor_route" "routing_rule" {
51+
name = var.routing_rule_name
52+
cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.fd.id
53+
cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.fd.id
54+
cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.fd.id]
55+
supported_protocols = var.accepted_protocols
56+
patterns_to_match = var.patterns_to_match
57+
forwarding_protocol = "MatchRequest"
58+
enabled = true
59+
https_redirect_enabled = false
60+
link_to_default_domain = true
61+
}

3_networking/front-door/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# outputs.tf
2+
# This file defines the outputs for the Front Door configuration.
3+
4+
output "front_door_id" {
5+
description = "The ID of the Front Door profile"
6+
value = azurerm_cdn_frontdoor_profile.fd.id
7+
}
8+
9+
output "front_door_frontend_endpoint" {
10+
description = "The frontend endpoint hostname of the Front Door"
11+
value = azurerm_cdn_frontdoor_endpoint.fd.host_name
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# provider.tf
2+
# This file configures the Azure provider to interact with Azure resources.
3+
# It specifies the required provider and its version, along with provider-specific configurations.
4+
5+
terraform {
6+
required_version = ">= 1.8, < 2.0"
7+
# Specify the required provider and its version
8+
required_providers {
9+
azurerm = {
10+
source = "hashicorp/azurerm" # Source of the AzureRM provider
11+
version = "~> 4.16.0" # Version of the AzureRM provider
12+
}
13+
}
14+
}
15+
16+
provider "azurerm" {
17+
features {} # Enable all features for the AzureRM provider
18+
subscription_id = var.subscription_id # Use the subscription ID variable
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# terraform.tfvars
2+
# This file provides default values for the variables defined in variables.tf.
3+
# These values can be overridden by specifying different values during Terraform execution.
4+
5+
# Azure Subscription
6+
subscription_id = "" # your-subscription-id
7+
8+
# Resource Group
9+
resource_group_name = "RG-frontdoor-test"
10+
location = "eastus"
11+
12+
# Front Door Configuration
13+
front_door_name = "myfrontdoorprofilebrown"
14+
backend_host = "mybackendtestbrown.example.com"
15+
16+
# Frontend Endpoint Configuration
17+
frontend_endpoint_name = "frontendEndpoint"
18+
19+
# Health Probe Configuration
20+
health_probe_path = "/"
21+
health_probe_protocol = "Http"
22+
23+
# Routing Rule Configuration
24+
routing_rule_name = "routingRule1"
25+
accepted_protocols = ["Http", "Https"]
26+
patterns_to_match = ["/*"]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# variables.tf
2+
# This file defines the input variables used in the Terraform configuration.
3+
4+
variable "subscription_id" {
5+
description = "The Azure subscription ID"
6+
type = string
7+
}
8+
9+
variable "resource_group_name" {
10+
description = "The name of the resource group"
11+
type = string
12+
}
13+
14+
variable "location" {
15+
description = "The Azure region to deploy resources"
16+
type = string
17+
}
18+
19+
variable "front_door_name" {
20+
description = "The name of the Azure Front Door Standard profile"
21+
type = string
22+
}
23+
24+
variable "backend_host" {
25+
description = "The backend host (FQDN or IP) where Front Door will route traffic"
26+
type = string
27+
}
28+
29+
variable "frontend_endpoint_name" {
30+
description = "The name of the Front Door frontend endpoint"
31+
type = string
32+
}
33+
34+
variable "health_probe_path" {
35+
description = "The path used for health probing"
36+
type = string
37+
default = "/"
38+
}
39+
40+
variable "health_probe_protocol" {
41+
description = "The protocol for health probing (Http or Https)"
42+
type = string
43+
default = "Http"
44+
}
45+
46+
variable "routing_rule_name" {
47+
description = "The name of the routing rule"
48+
type = string
49+
}
50+
51+
variable "accepted_protocols" {
52+
description = "List of accepted protocols for routing"
53+
type = list(string)
54+
default = ["Http", "Https"]
55+
}
56+
57+
variable "patterns_to_match" {
58+
description = "URL patterns for request matching"
59+
type = list(string)
60+
default = ["/*"]
61+
}

0 commit comments

Comments
 (0)