|
1 | 1 | ---
|
2 |
| -title: 'Quickstart: Create a Azure Front Door Standard/Premium profile using Terraform' |
| 2 | +title: 'Quickstart: Create an Azure Front Door Standard/Premium profile using Terraform' |
3 | 3 | description: This quickstart describes how to create an Azure Front Door Standard/Premium using Terraform.
|
4 | 4 | services: front-door
|
5 | 5 | author: johndowns
|
@@ -33,205 +33,27 @@ The steps in this article were tested with the following Terraform and Terraform
|
33 | 33 |
|
34 | 34 | 1. Create a file named `providers.tf` and insert the following code:
|
35 | 35 |
|
36 |
| - ```terraform |
37 |
| - # Configure the Azure provider |
38 |
| - terraform { |
39 |
| - required_providers { |
40 |
| - azurerm = { |
41 |
| - source = "hashicorp/azurerm" |
42 |
| - version = "~> 3.27.0" |
43 |
| - } |
44 |
| - |
45 |
| - random = { |
46 |
| - source = "hashicorp/random" |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - required_version = ">= 1.1.0" |
51 |
| - } |
52 |
| - |
53 |
| - provider "azurerm" { |
54 |
| - features {} |
55 |
| - } |
56 |
| - ``` |
| 36 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/providers.tf)] |
57 | 37 |
|
58 | 38 | 1. Create a file named `resource-group.tf` and insert the following code:
|
59 | 39 |
|
60 |
| - ```terraform |
61 |
| - resource "azurerm_resource_group" "my_resource_group" { |
62 |
| - name = var.resource_group_name |
63 |
| - location = var.location |
64 |
| - } |
65 |
| - ``` |
| 40 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/resource-group.tf)] |
66 | 41 |
|
67 | 42 | 1. Create a file named `app-service.tf` and insert the following code:
|
68 | 43 |
|
69 |
| - ```terraform |
70 |
| - locals { |
71 |
| - app_name = "myapp-${lower(random_id.app_name.hex)}" |
72 |
| - app_service_plan_name = "AppServicePlan" |
73 |
| - } |
74 |
| - |
75 |
| - resource "azurerm_service_plan" "app_service_plan" { |
76 |
| - name = local.app_service_plan_name |
77 |
| - location = var.location |
78 |
| - resource_group_name = azurerm_resource_group.my_resource_group.name |
79 |
| - |
80 |
| - sku_name = var.app_service_plan_sku_name |
81 |
| - os_type = "Windows" |
82 |
| - worker_count = var.app_service_plan_capacity |
83 |
| - } |
84 |
| - |
85 |
| - resource "azurerm_windows_web_app" "app" { |
86 |
| - name = local.app_name |
87 |
| - location = var.location |
88 |
| - resource_group_name = azurerm_resource_group.my_resource_group.name |
89 |
| - service_plan_id = azurerm_service_plan.app_service_plan.id |
90 |
| - |
91 |
| - https_only = true |
92 |
| - |
93 |
| - site_config { |
94 |
| - ftps_state = "Disabled" |
95 |
| - minimum_tls_version = "1.2" |
96 |
| - ip_restriction = [ { |
97 |
| - service_tag = "AzureFrontDoor.Backend" |
98 |
| - ip_address = null |
99 |
| - virtual_network_subnet_id = null |
100 |
| - action = "Allow" |
101 |
| - priority = 100 |
102 |
| - headers = [ { |
103 |
| - x_azure_fdid = [ azurerm_cdn_frontdoor_profile.my_front_door.resource_guid ] |
104 |
| - x_fd_health_probe = [] |
105 |
| - x_forwarded_for = [] |
106 |
| - x_forwarded_host = [] |
107 |
| - } ] |
108 |
| - name = "Allow traffic from Front Door" |
109 |
| - } ] |
110 |
| - } |
111 |
| - } |
112 |
| - ``` |
| 44 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/app-service.tf)] |
113 | 45 |
|
114 | 46 | 1. Create a file named `front-door.tf` and insert the following code:
|
115 | 47 |
|
116 |
| - ```terraform |
117 |
| - locals { |
118 |
| - front_door_profile_name = "MyFrontDoor" |
119 |
| - front_door_endpoint_name = "afd-${lower(random_id.front_door_endpoint_name.hex)}" |
120 |
| - front_door_origin_group_name = "MyOriginGroup" |
121 |
| - front_door_origin_name = "MyAppServiceOrigin" |
122 |
| - front_door_route_name = "MyRoute" |
123 |
| - } |
124 |
| - |
125 |
| - resource "azurerm_cdn_frontdoor_profile" "my_front_door" { |
126 |
| - name = local.front_door_profile_name |
127 |
| - resource_group_name = azurerm_resource_group.my_resource_group.name |
128 |
| - sku_name = var.front_door_sku_name |
129 |
| - } |
130 |
| - |
131 |
| - resource "azurerm_cdn_frontdoor_endpoint" "my_endpoint" { |
132 |
| - name = local.front_door_endpoint_name |
133 |
| - cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.my_front_door.id |
134 |
| - } |
135 |
| - |
136 |
| - resource "azurerm_cdn_frontdoor_origin_group" "my_origin_group" { |
137 |
| - name = local.front_door_origin_group_name |
138 |
| - cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.my_front_door.id |
139 |
| - session_affinity_enabled = true |
140 |
| - |
141 |
| - load_balancing { |
142 |
| - sample_size = 4 |
143 |
| - successful_samples_required = 3 |
144 |
| - } |
145 |
| - |
146 |
| - health_probe { |
147 |
| - path = "/" |
148 |
| - request_type = "HEAD" |
149 |
| - protocol = "Https" |
150 |
| - interval_in_seconds = 100 |
151 |
| - } |
152 |
| - } |
153 |
| - |
154 |
| - resource "azurerm_cdn_frontdoor_origin" "my_app_service_origin" { |
155 |
| - name = local.front_door_origin_name |
156 |
| - cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.my_origin_group.id |
157 |
| - |
158 |
| - enabled = true |
159 |
| - host_name = azurerm_windows_web_app.app.default_hostname |
160 |
| - http_port = 80 |
161 |
| - https_port = 443 |
162 |
| - origin_host_header = azurerm_windows_web_app.app.default_hostname |
163 |
| - priority = 1 |
164 |
| - weight = 1000 |
165 |
| - certificate_name_check_enabled = true |
166 |
| - } |
167 |
| - |
168 |
| - resource "azurerm_cdn_frontdoor_route" "my_route" { |
169 |
| - name = local.front_door_route_name |
170 |
| - cdn_frontdoor_endpoint_id = azurerm_cdn_frontdoor_endpoint.my_endpoint.id |
171 |
| - cdn_frontdoor_origin_group_id = azurerm_cdn_frontdoor_origin_group.my_origin_group.id |
172 |
| - cdn_frontdoor_origin_ids = [azurerm_cdn_frontdoor_origin.my_app_service_origin.id] |
173 |
| - |
174 |
| - supported_protocols = ["Http", "Https"] |
175 |
| - patterns_to_match = ["/*"] |
176 |
| - forwarding_protocol = "HttpsOnly" |
177 |
| - link_to_default_domain = true |
178 |
| - https_redirect_enabled = true |
179 |
| - } |
180 |
| - ``` |
| 48 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/front-door.tf)] |
181 | 49 |
|
182 | 50 | 1. Create a file named `variables.tf` and insert the following code:
|
183 | 51 |
|
184 |
| - ```terraform |
185 |
| - variable "location" { |
186 |
| - type = string |
187 |
| - default = "westus2" |
188 |
| - } |
189 |
| - |
190 |
| - variable "resource_group_name" { |
191 |
| - type = string |
192 |
| - default = "FrontDoor" |
193 |
| - } |
194 |
| - |
195 |
| - variable "app_service_plan_sku_name" { |
196 |
| - type = string |
197 |
| - default = "S1" |
198 |
| - } |
199 |
| - |
200 |
| - variable "app_service_plan_capacity" { |
201 |
| - type = number |
202 |
| - default = 1 |
203 |
| - } |
204 |
| - |
205 |
| - variable "app_service_plan_sku_tier_name" { |
206 |
| - type = string |
207 |
| - default = "Standard" |
208 |
| - } |
209 |
| - |
210 |
| - variable "front_door_sku_name" { |
211 |
| - type = string |
212 |
| - default = "Standard_AzureFrontDoor" |
213 |
| - validation { |
214 |
| - condition = contains(["Standard_AzureFrontDoor", "Premium_AzureFrontDoor"], var.front_door_sku_name) |
215 |
| - error_message = "The SKU value must be Standard_AzureFrontDoor or Premium_AzureFrontDoor." |
216 |
| - } |
217 |
| - } |
218 |
| - |
219 |
| - resource "random_id" "app_name" { |
220 |
| - byte_length = 8 |
221 |
| - } |
222 |
| - |
223 |
| - resource "random_id" "front_door_endpoint_name" { |
224 |
| - byte_length = 8 |
225 |
| - } |
226 |
| - ``` |
| 52 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/variables.tf)] |
227 | 53 |
|
228 | 54 | 1. Create a file named `outputs.tf` and insert the following code:
|
229 | 55 |
|
230 |
| - ```terraform |
231 |
| - output "frontDoorEndpointHostName" { |
232 |
| - value = azurerm_cdn_frontdoor_endpoint.my_endpoint.host_name |
233 |
| - } |
234 |
| - ``` |
| 56 | + [!code-terraform[master](../../terraform/quickstart/101-front-door-standard-premium/outputs.tf)] |
235 | 57 |
|
236 | 58 | ## Initialize Terraform
|
237 | 59 |
|
|
0 commit comments