Merge pull request #121 from johndowns/quickstart-101-front-door-classic

Add quickstart for Front Door (classic)
This commit is contained in:
Mark Gray (MSFT) 2022-11-21 13:42:38 -08:00 committed by GitHub
commit fb65ceaa11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 231 additions and 0 deletions

View File

@ -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
}
}
}

View File

@ -0,0 +1,20 @@
# Configure the Azure provider
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.27.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.4.3"
}
}
required_version = ">= 1.1.0"
}
provider "azurerm" {
features {}
}

View File

@ -0,0 +1,132 @@
# 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). |
| `random_id` | A random identifier generator to generate a unique Front Door resource name. |
## Variables
| 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
```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 = "<your backend hostname>"
+ enabled = true
+ host_header = "<your backend hostname>"
+ 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.
```

View File

@ -0,0 +1,8 @@
resource "azurerm_resource_group" "my_resource_group" {
name = var.resource_group_name
location = var.location
}
resource "random_id" "front_door_name" {
byte_length = 8
}

View File

@ -0,0 +1,13 @@
variable "location" {
type = string
default = "westus2"
}
variable "resource_group_name" {
type = string
default = "FrontDoor"
}
variable "backend_address" {
type = string
}