From c008240f611477f20c381a8f720af07d4daad996 Mon Sep 17 00:00:00 2001 From: John Downs Date: Tue, 25 Oct 2022 10:13:53 +1300 Subject: [PATCH 1/3] Add quickstart for Front Door (classic) --- .../101-front-door-classic/front-door.tf | 58 ++++++++ .../101-front-door-classic/providers.tf | 19 +++ quickstart/101-front-door-classic/readme.md | 131 ++++++++++++++++++ .../101-front-door-classic/resource-group.tf | 4 + .../101-front-door-classic/variables.tf | 17 +++ 5 files changed, 229 insertions(+) create mode 100644 quickstart/101-front-door-classic/front-door.tf create mode 100644 quickstart/101-front-door-classic/providers.tf create mode 100644 quickstart/101-front-door-classic/readme.md create mode 100644 quickstart/101-front-door-classic/resource-group.tf create mode 100644 quickstart/101-front-door-classic/variables.tf diff --git a/quickstart/101-front-door-classic/front-door.tf b/quickstart/101-front-door-classic/front-door.tf new file mode 100644 index 00000000..314d74ea --- /dev/null +++ b/quickstart/101-front-door-classic/front-door.tf @@ -0,0 +1,58 @@ +locals { + front_door_name = "afd-${lower(random_id.front_door_name.hex)}" + front_door_frontend_endpoint_name = "frontEndEndpoint" + front_door_load_balancing_settings_name = "loadBalancingSettings" + front_door_health_probe_settings_name = "healthProbeSettings" + front_door_routing_rule_name = "routingRule" + front_door_backend_pool_name = "backendPool" +} + +resource "azurerm_frontdoor" "my_front_door" { + name = local.front_door_name + resource_group_name = azurerm_resource_group.my_resource_group.name + + frontend_endpoint { + name = local.front_door_frontend_endpoint_name + host_name = "${local.front_door_name}.azurefd.net" + session_affinity_enabled = false + } + + backend_pool_load_balancing { + name = local.front_door_load_balancing_settings_name + sample_size = 4 + successful_samples_required = 2 + } + + backend_pool_health_probe { + name = local.front_door_health_probe_settings_name + path = "/" + protocol = "Http" + interval_in_seconds = 120 + } + + backend_pool { + name = local.front_door_backend_pool_name + backend { + host_header = var.backend_address + address = var.backend_address + http_port = 80 + https_port = 443 + weight = 50 + priority = 1 + } + + load_balancing_name = local.front_door_load_balancing_settings_name + health_probe_name = local.front_door_health_probe_settings_name + } + + routing_rule { + name = local.front_door_routing_rule_name + accepted_protocols = ["Http", "Https"] + patterns_to_match = ["/*"] + frontend_endpoints = [local.front_door_frontend_endpoint_name] + forwarding_configuration { + forwarding_protocol = "MatchRequest" + backend_pool_name = local.front_door_backend_pool_name + } + } +} diff --git a/quickstart/101-front-door-classic/providers.tf b/quickstart/101-front-door-classic/providers.tf new file mode 100644 index 00000000..2a4539cd --- /dev/null +++ b/quickstart/101-front-door-classic/providers.tf @@ -0,0 +1,19 @@ +# Configure the Azure provider +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.27.0" + } + + random = { + source = "hashicorp/random" + } + } + + required_version = ">= 1.1.0" +} + +provider "azurerm" { + features {} +} diff --git a/quickstart/101-front-door-classic/readme.md b/quickstart/101-front-door-classic/readme.md new file mode 100644 index 00000000..3f083494 --- /dev/null +++ b/quickstart/101-front-door-classic/readme.md @@ -0,0 +1,131 @@ +# Azure Front Door (classic) + +This template deploys an [Azure Front Door (classic)](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/frontdoor). + +## Resources + +| Terraform Resource Type | Description | +| - | - | +| `azurerm_resource_group` | The resource group for all the deployed resources.| +| `azurerm_frontdoor` | The Front Door (classic). | + +## Variables + +| Name | Description | +|-|-| +| `location` | The location for all the deployed resources. | +| `resource_group_name` | The name of the resource group to deploy. | +| `backend_address` | The host name or IP address of the backend application. | + +## Example + +```bash +$ terraform plan -out main.tfplan + +Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + + create + +Terraform will perform the following actions: + + # azurerm_frontdoor.my_front_door will be created + + resource "azurerm_frontdoor" "my_front_door" { + + backend_pool_health_probes = (known after apply) + + backend_pool_load_balancing_settings = (known after apply) + + backend_pools = (known after apply) + + cname = (known after apply) + + explicit_resource_order = (known after apply) + + frontend_endpoints = (known after apply) + + header_frontdoor_id = (known after apply) + + id = (known after apply) + + load_balancer_enabled = true + + name = (known after apply) + + resource_group_name = "FrontDoor" + + routing_rules = (known after apply) + + + backend_pool { + + health_probe_name = "healthProbeSettings" + + id = (known after apply) + + load_balancing_name = "loadBalancingSettings" + + name = "backendPool" + + + backend { + + address = "" + + enabled = true + + host_header = "" + + http_port = 80 + + https_port = 443 + + priority = 1 + + weight = 50 + } + } + + + backend_pool_health_probe { + + enabled = true + + id = (known after apply) + + interval_in_seconds = 120 + + name = "healthProbeSettings" + + path = "/" + + probe_method = "GET" + + protocol = "Http" + } + + + backend_pool_load_balancing { + + additional_latency_milliseconds = 0 + + id = (known after apply) + + name = "loadBalancingSettings" + + sample_size = 4 + + successful_samples_required = 2 + } + + + frontend_endpoint { + + host_name = (known after apply) + + id = (known after apply) + + name = "frontEndEndpoint" + + session_affinity_enabled = false + + session_affinity_ttl_seconds = 0 + } + + + routing_rule { + + accepted_protocols = [ + + "Http", + + "Https", + ] + + enabled = true + + frontend_endpoints = [ + + "frontEndEndpoint", + ] + + id = (known after apply) + + name = "routingRule" + + patterns_to_match = [ + + "/*", + ] + + + forwarding_configuration { + + backend_pool_name = "backendPool" + + cache_enabled = false + + cache_query_parameter_strip_directive = "StripAll" + + cache_use_dynamic_compression = false + + forwarding_protocol = "MatchRequest" + } + } + } + + # azurerm_resource_group.my_resource_group will be created + + resource "azurerm_resource_group" "my_resource_group" { + + id = (known after apply) + + location = "westus2" + + name = "FrontDoor" + } + + # random_id.front_door_name will be created + + resource "random_id" "front_door_name" { + + b64_std = (known after apply) + + b64_url = (known after apply) + + byte_length = 8 + + dec = (known after apply) + + hex = (known after apply) + + id = (known after apply) + } + +Plan: 3 to add, 0 to change, 0 to destroy. +``` diff --git a/quickstart/101-front-door-classic/resource-group.tf b/quickstart/101-front-door-classic/resource-group.tf new file mode 100644 index 00000000..85fae84e --- /dev/null +++ b/quickstart/101-front-door-classic/resource-group.tf @@ -0,0 +1,4 @@ +resource "azurerm_resource_group" "my_resource_group" { + name = var.resource_group_name + location = var.location +} diff --git a/quickstart/101-front-door-classic/variables.tf b/quickstart/101-front-door-classic/variables.tf new file mode 100644 index 00000000..3a6446c3 --- /dev/null +++ b/quickstart/101-front-door-classic/variables.tf @@ -0,0 +1,17 @@ +variable "location" { + type = string + default = "westus2" +} + +variable "resource_group_name" { + type = string + default = "FrontDoor" +} + +variable "backend_address" { + type = string +} + +resource "random_id" "front_door_name" { + byte_length = 8 +} From eaa4dedbd404941ab6a3357abbc1ebf81c5b49f6 Mon Sep 17 00:00:00 2001 From: John Downs Date: Fri, 18 Nov 2022 12:41:32 +1300 Subject: [PATCH 2/3] Updates from PR review --- quickstart/101-front-door-classic/providers.tf | 1 + quickstart/101-front-door-classic/readme.md | 3 ++- quickstart/101-front-door-classic/resource-group.tf | 4 ++++ quickstart/101-front-door-classic/variables.tf | 4 ---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/quickstart/101-front-door-classic/providers.tf b/quickstart/101-front-door-classic/providers.tf index 2a4539cd..c8990b6e 100644 --- a/quickstart/101-front-door-classic/providers.tf +++ b/quickstart/101-front-door-classic/providers.tf @@ -8,6 +8,7 @@ terraform { random = { source = "hashicorp/random" + version = "~> 3.4.3" } } diff --git a/quickstart/101-front-door-classic/readme.md b/quickstart/101-front-door-classic/readme.md index 3f083494..e7f1186e 100644 --- a/quickstart/101-front-door-classic/readme.md +++ b/quickstart/101-front-door-classic/readme.md @@ -6,8 +6,9 @@ This template deploys an [Azure Front Door (classic)](https://registry.terraform | Terraform Resource Type | Description | | - | - | -| `azurerm_resource_group` | The resource group for all the deployed resources.| +| `azurerm_resource_group` | The resource group for all the deployed resources. | | `azurerm_frontdoor` | The Front Door (classic). | +| `random_id` | A random identifier generator to generate a unique Front Door resource name. | ## Variables diff --git a/quickstart/101-front-door-classic/resource-group.tf b/quickstart/101-front-door-classic/resource-group.tf index 85fae84e..90cf26f1 100644 --- a/quickstart/101-front-door-classic/resource-group.tf +++ b/quickstart/101-front-door-classic/resource-group.tf @@ -2,3 +2,7 @@ resource "azurerm_resource_group" "my_resource_group" { name = var.resource_group_name location = var.location } + +resource "random_id" "front_door_name" { + byte_length = 8 +} diff --git a/quickstart/101-front-door-classic/variables.tf b/quickstart/101-front-door-classic/variables.tf index 3a6446c3..d9027f9d 100644 --- a/quickstart/101-front-door-classic/variables.tf +++ b/quickstart/101-front-door-classic/variables.tf @@ -11,7 +11,3 @@ variable "resource_group_name" { variable "backend_address" { type = string } - -resource "random_id" "front_door_name" { - byte_length = 8 -} From 497661a7aabc390b16da501747313863e77a68fe Mon Sep 17 00:00:00 2001 From: John Downs Date: Fri, 18 Nov 2022 12:48:30 +1300 Subject: [PATCH 3/3] Update readme --- quickstart/101-front-door-classic/readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quickstart/101-front-door-classic/readme.md b/quickstart/101-front-door-classic/readme.md index e7f1186e..05f442d1 100644 --- a/quickstart/101-front-door-classic/readme.md +++ b/quickstart/101-front-door-classic/readme.md @@ -12,11 +12,11 @@ This template deploys an [Azure Front Door (classic)](https://registry.terraform ## Variables -| Name | Description | -|-|-| -| `location` | The location for all the deployed resources. | -| `resource_group_name` | The name of the resource group to deploy. | -| `backend_address` | The host name or IP address of the backend application. | +| Name | Description | Default Value | +|-|-|-| +| `location` | The location for all the deployed resources. | `westus2` | +| `resource_group_name` | The name of the resource group to deploy. | `FrontDoor` | +| `backend_address` | The host name or IP address of the backend application. | | ## Example