1
1
module "functionapp" {
2
- for_each = local. function_app_map
3
-
4
2
source = " ../../../dtos-devops-templates/infrastructure/modules/function-app"
5
3
6
- function_app_name = " ${ module . regions_config [each . value . region ]. names . function-app } -${ lower (each . value . name_suffix ) } "
7
- resource_group_name = azurerm_resource_group. core [each . value . region ]. name
8
- location = each . value . region
4
+ function_app_name = " ${ module . regions_config [local . primary_region ]. names . function-app } -${ local . name_suffix } "
5
+ resource_group_name = azurerm_resource_group. core [local . primary_region ]. name
6
+ location = local . primary_region
9
7
10
- app_settings = each . value . app_settings
8
+ app_settings = local . app_settings
11
9
12
10
log_analytics_workspace_id = data. terraform_remote_state . audit . outputs . log_analytics_workspace_id [local . primary_region ]
13
11
monitor_diagnostic_setting_function_app_enabled_logs = local. monitor_diagnostic_setting_function_app_enabled_logs
14
12
monitor_diagnostic_setting_function_app_metrics = local. monitor_diagnostic_setting_function_app_metrics
15
13
16
14
public_network_access_enabled = var. features . public_network_access_enabled
17
- vnet_integration_subnet_id = module. subnets [" ${ module . regions_config [each . value . region ]. names . subnet } -apps" ]. id
15
+ vnet_integration_subnet_id = module. subnets [" ${ module . regions_config [local . primary_region ]. names . subnet } -apps" ]. id
18
16
19
- rbac_role_assignments = each . value . rbac_role_assignments
17
+ rbac_role_assignments = local . rbac_role_assignments
20
18
21
- asp_id = module. app-service-plan [" ${ each . value . app_service_plan_key } -${ each . value . region } " ]. app_service_plan_id
19
+ asp_id = module. app-service-plan [" ${ var . app_service_plan_key } -${ local . primary_region } " ]. app_service_plan_id
22
20
23
21
# Use the storage account assigned identity for the Function Apps:
24
- storage_account_name = module. storage [" fnapp-${ each . value . region } " ]. storage_account_name
25
- storage_account_access_key = var. function_apps . storage_uses_managed_identity == true ? null : module. storage [" fnapp-${ each . value . region } " ]. storage_account_primary_access_key
26
- storage_uses_managed_identity = var. function_apps . storage_uses_managed_identity
22
+ storage_account_name = module. storage [" fnapp-${ local . primary_region } " ]. storage_account_name
23
+ storage_account_access_key = var. function_app . storage_uses_managed_identity == true ? null : module. storage [" fnapp-${ local . primary_region } " ]. storage_account_primary_access_key
24
+ storage_uses_managed_identity = var. function_app . storage_uses_managed_identity
27
25
28
26
# Connection string for Application Insights:
29
27
ai_connstring = data. azurerm_application_insights . ai . connection_string
30
28
31
29
# Use the ACR assigned identity for the Function Apps:
32
- cont_registry_use_mi = var. function_apps . cont_registry_use_mi
30
+ cont_registry_use_mi = var. function_app . cont_registry_use_mi
33
31
34
32
# Other Function App configuration settings:
35
- always_on = var. function_apps . always_on
36
- worker_32bit = var. function_apps . worker_32bit
33
+ always_on = var. function_app . always_on
34
+ worker_32bit = var. function_app . worker_32bit
37
35
38
36
acr_mi_client_id = data. azurerm_user_assigned_identity . acr_mi . client_id
39
37
acr_login_server = data. azurerm_container_registry . acr . login_server
40
38
41
39
# Use the ACR assigned identity for the Function Apps too:
42
- assigned_identity_ids = var. function_apps . cont_registry_use_mi ? [data . azurerm_user_assigned_identity . acr_mi . id ] : []
40
+ assigned_identity_ids = var. function_app . cont_registry_use_mi ? [data . azurerm_user_assigned_identity . acr_mi . id ] : []
43
41
44
- image_tag = var. function_apps . docker_env_tag
45
- image_name = " ${ var . function_apps . docker_img_prefix } -${ lower (each . value . name_suffix )} "
42
+ image_tag = var. function_app . docker_env_tag
43
+ image_name = " ${ var . function_app . docker_img_prefix } -${ lower (local . name_suffix )} "
46
44
47
45
# Private Endpoint Configuration if enabled
48
46
private_endpoint_properties = var. features . private_endpoints_enabled ? {
49
- private_dns_zone_ids = [data.terraform_remote_state.hub.outputs.private_dns_zones[" ${ each . value . region } -app_services" ].id]
47
+ private_dns_zone_ids = [data.terraform_remote_state.hub.outputs.private_dns_zones[" ${ local . primary_region } -app_services" ].id]
50
48
private_endpoint_enabled = var.features.private_endpoints_enabled
51
- private_endpoint_subnet_id = module.subnets[" ${ module . regions_config [each . value . region ]. names . subnet } -pep" ].id
52
- private_endpoint_resource_group_name = azurerm_resource_group.rg_private_endpoints[each.value.region ].name
49
+ private_endpoint_subnet_id = module.subnets[" ${ module . regions_config [local . primary_region ]. names . subnet } -pep" ].id
50
+ private_endpoint_resource_group_name = azurerm_resource_group.rg_private_endpoints[local.primary_region ].name
53
51
private_service_connection_is_manual = var.features.private_service_connection_is_manual
54
52
} : null
55
53
@@ -60,95 +58,44 @@ module "functionapp" {
60
58
61
59
62
60
locals {
61
+ name_suffix = " communication_management"
63
62
primary_region = [for k , v in var . regions : k if v . is_primary_region ][0 ]
64
-
65
- app_settings_common = {
66
- DOCKER_ENABLE_CI = var.function_apps.docker_CI_enable
67
- REMOTE_DEBUGGING_ENABLED = var.function_apps.remote_debugging_enabled
68
- WEBSITES_ENABLE_APP_SERVICE_STORAGE = var.function_apps.enable_appsrv_storage
69
- WEBSITE_PULL_IMAGE_OVER_VNET = var.features.private_endpoints_enabled
70
- FUNCTIONS_WORKER_RUNTIME = " python"
71
- }
72
-
73
- # There are multiple Function Apps and possibly multiple regions.
74
- # We cannot nest for loops inside a map, so first iterate all permutations of both as a list of objects...
75
- function_app_config_object_list = flatten ([
76
- for region in keys (var. regions ) : [
77
- for function , config in var . function_apps . fa_config : merge (
78
- {
79
- region = region # 1st iterator
80
- function = function # 2nd iterator
81
- },
82
- config , # the rest of the key/value pairs for a specific function
83
- {
84
- app_settings = merge (
85
- local. app_settings_common ,
86
- config. env_vars_static ,
87
-
88
- # Dynamic env vars which cannot be stored in tfvars file
89
- function == " message-status" ? {
90
- APPLICATION_ID = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . application_id [region ]. versionless_id } )"
91
- NOTIFY_API_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . notify_api_key [region ]. versionless_id } )"
92
- } : {},
93
- function == " notify" ? {
94
- OAUTH2_API_KID = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . oauth2_api_kid [region ]. versionless_id } )"
95
- OAUTH2_API_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . oauth2_api_key [region ]. versionless_id } )"
96
- PRIVATE_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_key . private_key [region ]. versionless_id } )"
97
- } : {},
98
- function == " process-pilot-data" ? {
99
- AzureWebJobsStorage__accountName = module.storage[" fnapp-${ region } " ].storage_account_name
100
- NOTIFY_FUNCTION_URL = format (
101
- " https://%s-%s.azurewebsites.net/api/%s/message/send" ,
102
- module. regions_config [region ]. names [" function-app" ],
103
- var. function_apps . fa_config [" notify" ]. name_suffix ,
104
- lower (var. function_apps . fa_config [" notify" ]. function_endpoint_name )
105
- )
106
- } : {},
107
-
108
- # Dynamic reference to Key Vault
109
- length (config. key_vault_url ) > 0 ? {
110
- (config. key_vault_url ) = module.key_vault[region].key_vault_url
111
- } : {},
112
-
113
- # Database
114
- config. database_required ? {
115
- DATABASE_NAME = " communication_management"
116
- DATABASE_HOST = " ${ module . regions_config [region ]. names . postgres-sql-server } .postgres.database.azure.com"
117
- DATABASE_USER = " commgt_db_user"
118
- DATABASE_PASSWORD = " @Microsoft.KeyVault(SecretUri=${ module . postgresql_flexible_db [region ]. db_admin_pwd_keyvault_secret } )"
119
- # DATABASE_USER = var.postgresql.postgres_sql_admin_group
120
- } : {}
121
-
122
- )
123
-
124
- # These RBAC assignments are for the Function Apps only
125
- rbac_role_assignments = flatten ([
126
-
127
- # Key Vault
128
- var . key_vault != {} ? [
129
- for role in local . rbac_roles_key_vault_user : {
130
- role_definition_name = role
131
- scope = module . key_vault [region ]. key_vault_id
132
- }
133
- ] : [],
134
-
135
- # Storage Accounts
136
- [
137
- for account in keys (var. storage_accounts ) : [
138
- for role in local . rbac_roles_storage : {
139
- role_definition_name = role
140
- scope = module . storage [" ${ account } -${ region } " ]. storage_account_id
141
- }
142
- ]
143
- ]
144
- ])
63
+ app_settings = merge (
64
+ var. function_app . env_vars_static ,
65
+ {
66
+ DOCKER_ENABLE_CI = var.function_app.docker_CI_enable
67
+ FUNCTIONS_WORKER_RUNTIME = " python"
68
+ REMOTE_DEBUGGING_ENABLED = var.function_app.remote_debugging_enabled
69
+ WEBSITES_ENABLE_APP_SERVICE_STORAGE = var.function_app.enable_appsrv_storage
70
+ WEBSITE_PULL_IMAGE_OVER_VNET = var.features.private_endpoints_enabled
71
+
72
+ DATABASE_NAME = " communication_management"
73
+ DATABASE_HOST = " ${ module . regions_config [var . regions . keys [0 ]]. names . postgres-sql-server } .postgres.database.azure.com"
74
+ DATABASE_USER = " commgt_db_user"
75
+ DATABASE_PASSWORD = " @Microsoft.KeyVault(SecretUri=${ module . postgresql_flexible_db [var . regions . keys [0 ]]. db_admin_pwd_keyvault_secret } )"
76
+
77
+ APPLICATION_ID = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . application_id [var . regions . keys [0 ]]. versionless_id } )"
78
+ NOTIFY_API_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . notify_api_key [var . regions . keys [0 ]]. versionless_id } )"
79
+ OAUTH2_API_KID = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . oauth2_api_kid [var . regions . keys [0 ]]. versionless_id } )"
80
+ OAUTH2_API_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_secret . oauth2_api_key [var . regions . keys [0 ]]. versionless_id } )"
81
+ PRIVATE_KEY = " @Microsoft.KeyVault(SecretUri=${ data . azurerm_key_vault_key . private_key [var . regions . keys [0 ]]. versionless_id } )"
82
+ }
83
+ )
84
+
85
+ rbac_role_assignments = flatten ([
86
+ var . key_vault != {} ? [
87
+ for role in local . rbac_roles_key_vault_user : {
88
+ role_definition_name = role
89
+ scope = module . key_vault [var . regions . keys [0 ]]. key_vault_id
90
+ }
91
+ ] : [],
92
+ [
93
+ for account in keys (var. storage_accounts ) : [
94
+ for role in local . rbac_roles_storage : {
95
+ role_definition_name = role
96
+ scope = module . storage [" ${ account } -${ var . regions . keys [0 ]} " ]. storage_account_id
145
97
}
146
- )
98
+ ]
147
99
]
148
100
])
149
-
150
- # ...then project the list of objects into a map with unique keys (combining the iterators), for consumption by a for_each meta argument
151
- function_app_map = {
152
- for object in local . function_app_config_object_list : " ${ object . function } -${ object . region } " => object
153
- }
154
101
}
0 commit comments