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-
421resource "azapi_resource" "function" {
432 type = " Microsoft.Web/sites@2022-09-01"
443 parent_id = azurerm_resource_group. app_rg . id
@@ -65,7 +24,7 @@ resource "azapi_resource" "function" {
6524 redundancyMode = " None"
6625 reserved = true
6726 scmSiteAlsoStopped = true
68- serverFarmId = azurerm_service_plan.service_plan.id
27+ serverFarmId = module.app_service_plan.service_plan_id
6928 storageAccountRequired = false
7029 vnetContentShareEnabled = true
7130 vnetImagePullEnabled = false # Set to 'true' when pulling image from private Azure Container Registry
@@ -91,7 +50,7 @@ resource "azapi_resource" "function" {
9150 appSettings = [
9251 {
9352 name = " APPLICATIONINSIGHTS_CONNECTION_STRING"
94- value = azurerm_application_insights .application_insights.connection_string
53+ value = module .application_insights.application_insights_connection_string
9554 },
9655 {
9756 name = " AZURE_SDK_TRACING_IMPLEMENTATION"
@@ -123,23 +82,23 @@ resource "azapi_resource" "function" {
12382 },
12483 {
12584 name = " WEBSITE_OS_TYPE"
126- value = azurerm_service_plan.service_plan.os_type
85+ value = module.app_service_plan.service_plan_os_type
12786 },
12887 {
12988 name = " WEBSITE_RUN_FROM_PACKAGE"
13089 value = " 0"
13190 },
13291 {
13392 name = " AzureWebJobsStorage__accountName"
134- value = azurerm_storage_account.storage.name
93+ value = module.storage_account.storage_account_name
13594 },
13695 {
13796 name = " AzureWebJobsSecretStorageType"
13897 value = " keyvault"
13998 },
14099 {
141100 name = " AzureWebJobsSecretStorageKeyVaultUri"
142- value = azurerm_key_vault .key_vault.vault_uri
101+ value = module .key_vault.key_vault_uri
143102 },
144103 {
145104 name = " WEBSITES_ENABLE_APP_SERVICE_STORAGE" # Disable when not running a container
@@ -219,11 +178,8 @@ resource "azapi_resource" "function" {
219178 # "properties.siteConfig.appSettings"
220179 # ]
221180 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 ,
227183 ]
228184}
229185
@@ -234,7 +190,7 @@ data "azurerm_monitor_diagnostic_categories" "diagnostic_categories_function" {
234190resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting_function" {
235191 name = " logAnalytics"
236192 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
238194
239195 dynamic "enabled_log" {
240196 iterator = entry
@@ -267,11 +223,20 @@ resource "azurerm_private_endpoint" "function_private_endpoint" {
267223 private_connection_resource_id = azapi_resource. function . id
268224 subresource_names = [" sites" ]
269225 }
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
275240 ]
276241 }
277242}
0 commit comments