1
- resource "azurerm_service_plan" "service_plan" {
2
- name = " ${ local . prefix } -asp001"
3
- location = var. location
4
- resource_group_name = azurerm_resource_group. app_rg . name
5
- tags = var. tags
6
-
7
- # maximum_elastic_worker_count = 20
8
- os_type = " Linux"
9
- per_site_scaling_enabled = false
10
- sku_name = var. function_sku
11
- worker_count = 1 # Update to '3' for production
12
- zone_balancing_enabled = false # Update to 'true' for production
13
- }
14
-
15
- data "azurerm_monitor_diagnostic_categories" "diagnostic_categories_service_plan" {
16
- resource_id = azurerm_service_plan. service_plan . id
17
- }
18
-
19
- resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting_service_plan" {
20
- name = " logAnalytics"
21
- target_resource_id = azurerm_service_plan. service_plan . id
22
- log_analytics_workspace_id = azurerm_log_analytics_workspace. log_analytics_workspace . id
23
-
24
- dynamic "enabled_log" {
25
- iterator = entry
26
- for_each = data. azurerm_monitor_diagnostic_categories . diagnostic_categories_service_plan . log_category_groups
27
- content {
28
- category_group = entry. value
29
- }
30
- }
31
-
32
- dynamic "metric" {
33
- iterator = entry
34
- for_each = data. azurerm_monitor_diagnostic_categories . diagnostic_categories_service_plan . metrics
35
- content {
36
- category = entry. value
37
- enabled = true
38
- }
39
- }
40
- }
41
-
42
1
resource "azapi_resource" "function" {
43
2
type = " Microsoft.Web/sites@2022-09-01"
44
3
parent_id = azurerm_resource_group. app_rg . id
@@ -65,7 +24,7 @@ resource "azapi_resource" "function" {
65
24
redundancyMode = " None"
66
25
reserved = true
67
26
scmSiteAlsoStopped = true
68
- serverFarmId = azurerm_service_plan.service_plan.id
27
+ serverFarmId = module.app_service_plan.service_plan_id
69
28
storageAccountRequired = false
70
29
vnetContentShareEnabled = true
71
30
vnetImagePullEnabled = false # Set to 'true' when pulling image from private Azure Container Registry
@@ -91,7 +50,7 @@ resource "azapi_resource" "function" {
91
50
appSettings = [
92
51
{
93
52
name = " APPLICATIONINSIGHTS_CONNECTION_STRING"
94
- value = azurerm_application_insights .application_insights.connection_string
53
+ value = module .application_insights.application_insights_connection_string
95
54
},
96
55
{
97
56
name = " AZURE_SDK_TRACING_IMPLEMENTATION"
@@ -123,23 +82,23 @@ resource "azapi_resource" "function" {
123
82
},
124
83
{
125
84
name = " WEBSITE_OS_TYPE"
126
- value = azurerm_service_plan.service_plan.os_type
85
+ value = module.app_service_plan.service_plan_os_type
127
86
},
128
87
{
129
88
name = " WEBSITE_RUN_FROM_PACKAGE"
130
89
value = " 0"
131
90
},
132
91
{
133
92
name = " AzureWebJobsStorage__accountName"
134
- value = azurerm_storage_account.storage.name
93
+ value = module.storage_account.storage_account_name
135
94
},
136
95
{
137
96
name = " AzureWebJobsSecretStorageType"
138
97
value = " keyvault"
139
98
},
140
99
{
141
100
name = " AzureWebJobsSecretStorageKeyVaultUri"
142
- value = azurerm_key_vault .key_vault.vault_uri
101
+ value = module .key_vault.key_vault_uri
143
102
},
144
103
{
145
104
name = " WEBSITES_ENABLE_APP_SERVICE_STORAGE" # Disable when not running a container
@@ -219,11 +178,8 @@ resource "azapi_resource" "function" {
219
178
# "properties.siteConfig.appSettings"
220
179
# ]
221
180
depends_on = [
222
- azurerm_private_endpoint . key_vault_private_endpoint ,
223
- azurerm_private_endpoint . storage_private_endpoint_blob ,
224
- azurerm_private_endpoint . storage_private_endpoint_file ,
225
- azurerm_private_endpoint . storage_private_endpoint_queue ,
226
- azurerm_private_endpoint . storage_private_endpoint_table ,
181
+ module . key_vault . key_vault_setup_completed ,
182
+ module . storage_account . storage_setup_completed ,
227
183
]
228
184
}
229
185
@@ -234,7 +190,7 @@ data "azurerm_monitor_diagnostic_categories" "diagnostic_categories_function" {
234
190
resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting_function" {
235
191
name = " logAnalytics"
236
192
target_resource_id = azapi_resource. function . id
237
- log_analytics_workspace_id = azurerm_log_analytics_workspace . log_analytics_workspace . id
193
+ log_analytics_workspace_id = var . log_analytics_workspace_id
238
194
239
195
dynamic "enabled_log" {
240
196
iterator = entry
@@ -267,11 +223,20 @@ resource "azurerm_private_endpoint" "function_private_endpoint" {
267
223
private_connection_resource_id = azapi_resource. function . id
268
224
subresource_names = [" sites" ]
269
225
}
270
- subnet_id = azapi_resource. subnet_services . id
271
- private_dns_zone_group {
272
- name = " ${ azapi_resource . function . name } -arecord"
273
- private_dns_zone_ids = [
274
- var . private_dns_zone_id_sites
226
+ subnet_id = azapi_resource. subnet_private_endpoints . id
227
+ dynamic "private_dns_zone_group" {
228
+ for_each = var. private_dns_zone_id_sites == " " ? [] : [1 ]
229
+ content {
230
+ name = " ${ azapi_resource . function . name } -arecord"
231
+ private_dns_zone_ids = [
232
+ var . private_dns_zone_id_sites
233
+ ]
234
+ }
235
+ }
236
+
237
+ lifecycle {
238
+ ignore_changes = [
239
+ private_dns_zone_group
275
240
]
276
241
}
277
242
}
0 commit comments