-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfunction-app.tf
162 lines (136 loc) · 7.82 KB
/
function-app.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
resource "azurerm_service_plan" "function_apps" {
count = local.enable_linux_function_apps ? 1 : 0
name = "${local.resource_prefix}-linux-serviceplan"
resource_group_name = local.resource_group.name
location = local.resource_group.location
os_type = "Linux"
sku_name = "Y1" // PAYG/Consumption plan
tags = local.tags
}
resource "azurerm_linux_function_app" "health_api" {
for_each = local.linux_function_health_insights_api
name = "${local.resource_prefix}-${each.key}"
resource_group_name = local.resource_group.name
location = local.resource_group.location
storage_account_name = azurerm_storage_account.function_app_backing[0].name
storage_account_access_key = azurerm_storage_account.function_app_backing[0].primary_access_key
service_plan_id = azurerm_service_plan.function_apps[0].id
ftp_publish_basic_authentication_enabled = each.value.ftp_publish_basic_authentication_enabled
webdeploy_publish_basic_authentication_enabled = each.value.webdeploy_publish_basic_authentication_enabled
https_only = true
key_vault_reference_identity_id = azurerm_user_assigned_identity.function_apps[each.key].id
zip_deploy_file = data.archive_file.azure_function[each.key].output_path
app_settings = merge(each.value.app_settings, {
"AZURE_CLIENT_ID" = azurerm_user_assigned_identity.function_apps[each.key].client_id
})
site_config {
always_on = false
application_insights_connection_string = local.enable_app_insights_integration ? azurerm_application_insights.function_apps[each.key].connection_string : null
application_insights_key = local.enable_app_insights_integration ? azurerm_application_insights.function_apps[each.key].instrumentation_key : null
app_scale_limit = 1
http2_enabled = true
ftps_state = each.value.ftp_publish_basic_authentication_enabled ? "FtpsOnly" : "Disabled"
ip_restriction_default_action = length(each.value.ipv4_access) > 0 ? "Deny" : "Allow"
scm_ip_restriction_default_action = length(each.value.ipv4_access) > 0 ? "Deny" : "Allow"
scm_use_main_ip_restriction = true
minimum_tls_version = "1.3"
cors {
allowed_origins = each.value.allowed_origins
support_credentials = contains(each.value.allowed_origins, "*") ? false : true
}
dynamic "ip_restriction" {
for_each = each.value.ipv4_access
content {
action = "Allow"
name = "AllowIPInbound${ip_restriction.value}"
ip_address = ip_restriction.value
}
}
application_stack {
python_version = lower(each.value.runtime) == "python" ? each.value.runtime_version : null
dotnet_version = lower(each.value.runtime) == "dotnet" ? each.value.runtime_version : null
java_version = lower(each.value.runtime) == "java" ? each.value.runtime_version : null
node_version = lower(each.value.runtime) == "node" ? each.value.runtime_version : null
}
}
identity {
type = "UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.function_apps[each.key].id
]
}
tags = merge(local.tags, {
"hidden-link: /app-insights-conn-string" : azurerm_application_insights.function_apps[each.key].connection_string,
"hidden-link: /app-insights-instrumentation-key" : azurerm_application_insights.function_apps[each.key].instrumentation_key,
"hidden-link: /app-insights-resource-id" : azurerm_application_insights.function_apps[each.key].id,
})
lifecycle {
replace_triggered_by = [terraform_data.function_app_package_sha[each.key]]
}
}
resource "azurerm_linux_function_app" "function_apps" {
for_each = local.linux_function_apps
name = "${local.environment}${each.key}"
resource_group_name = local.resource_group.name
location = local.resource_group.location
storage_account_name = azurerm_storage_account.function_app_backing[0].name
storage_account_access_key = azurerm_storage_account.function_app_backing[0].primary_access_key
service_plan_id = azurerm_service_plan.function_apps[0].id
ftp_publish_basic_authentication_enabled = each.value.ftp_publish_basic_authentication_enabled
webdeploy_publish_basic_authentication_enabled = each.value.webdeploy_publish_basic_authentication_enabled
https_only = true
key_vault_reference_identity_id = azurerm_user_assigned_identity.function_apps[each.key].id
app_settings = merge(each.value.app_settings, {
"AZURE_CLIENT_ID" = azurerm_user_assigned_identity.function_apps[each.key].client_id
})
site_config {
always_on = false
application_insights_connection_string = local.enable_app_insights_integration ? azurerm_application_insights.function_apps[each.key].connection_string : null
application_insights_key = local.enable_app_insights_integration ? azurerm_application_insights.function_apps[each.key].instrumentation_key : null
app_scale_limit = 1
http2_enabled = true
ftps_state = each.value.ftp_publish_basic_authentication_enabled ? "FtpsOnly" : "Disabled"
ip_restriction_default_action = length(each.value.ipv4_access) > 0 ? "Deny" : "Allow"
scm_ip_restriction_default_action = length(each.value.ipv4_access) > 0 ? "Deny" : "Allow"
scm_use_main_ip_restriction = true
minimum_tls_version = each.value.minimum_tls_version
cors {
allowed_origins = each.value.allowed_origins
support_credentials = contains(each.value.allowed_origins, "*") ? false : true
}
dynamic "ip_restriction" {
for_each = each.value.ipv4_access
content {
action = "Allow"
name = "AllowIPInbound${ip_restriction.value}"
ip_address = ip_restriction.value
}
}
application_stack {
python_version = lower(each.value.runtime) == "python" ? each.value.runtime_version : null
dotnet_version = lower(each.value.runtime) == "dotnet" ? each.value.runtime_version : null
java_version = lower(each.value.runtime) == "java" ? each.value.runtime_version : null
node_version = lower(each.value.runtime) == "node" ? each.value.runtime_version : null
}
}
identity {
type = "UserAssigned"
identity_ids = [
azurerm_user_assigned_identity.function_apps[each.key].id
]
}
tags = merge(local.tags, local.enable_app_insights_integration ? {
"hidden-link: /app-insights-conn-string" : azurerm_application_insights.function_apps[each.key].connection_string,
"hidden-link: /app-insights-instrumentation-key" : azurerm_application_insights.function_apps[each.key].instrumentation_key,
"hidden-link: /app-insights-resource-id" : azurerm_application_insights.function_apps[each.key].id,
} : {})
}
resource "azurerm_monitor_diagnostic_setting" "function_apps" {
for_each = merge(local.linux_function_apps, local.linux_function_health_insights_api)
name = "${azurerm_linux_function_app.health_api[each.key].name}-diagnostics"
target_resource_id = azurerm_linux_function_app.health_api[each.key].id
log_analytics_workspace_id = azurerm_log_analytics_workspace.function_app[0].id
enabled_log {
category = "FunctionAppLogs"
}
}