forked from Azure/terraform-azure-container-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
370 lines (320 loc) · 14.8 KB
/
main.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
locals {
container_app_environment_id = try(data.azurerm_container_app_environment.container_env[0].id, azurerm_container_app_environment.container_env[0].id)
}
resource "azurerm_log_analytics_workspace" "laws" {
count = var.log_analytics_workspace == null ? 1 : 0
location = var.location
name = var.log_analytics_workspace_name
resource_group_name = var.resource_group_name
allow_resource_only_permissions = var.log_analytics_workspace_allow_resource_only_permissions
cmk_for_query_forced = var.log_analytics_workspace_cmk_for_query_forced
daily_quota_gb = var.log_analytics_workspace_daily_quota_gb
internet_ingestion_enabled = var.log_analytics_workspace_internet_ingestion_enabled
internet_query_enabled = var.log_analytics_workspace_internet_query_enabled
local_authentication_disabled = var.log_analytics_workspace_local_authentication_disabled
reservation_capacity_in_gb_per_day = var.log_analytics_workspace_reservation_capacity_in_gb_per_day
retention_in_days = var.log_analytics_workspace_retention_in_days
sku = var.log_analytics_workspace_sku
tags = merge(var.log_analytics_workspace_tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "3c8fdedf05d02b33355d62341861ab3cd7f1ba6d"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-06-14 06:06:03"
avm_git_org = "Azure"
avm_git_repo = "terraform-azure-container-apps"
avm_yor_name = "laws"
avm_yor_trace = "da1eccc9-6a1e-4c2f-9f17-6617cbbe586a"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
}
data "azurerm_container_app_environment" "container_env" {
count = var.container_app_environment != null ? 1 : 0
name = var.container_app_environment.name
resource_group_name = var.container_app_environment.resource_group_name
}
resource "azurerm_container_app_environment" "container_env" {
count = var.container_app_environment == null ? 1 : 0
location = var.location
name = var.container_app_environment_name
resource_group_name = var.resource_group_name
infrastructure_subnet_id = var.container_app_environment_infrastructure_subnet_id
internal_load_balancer_enabled = var.container_app_environment_internal_load_balancer_enabled
log_analytics_workspace_id = try(azurerm_log_analytics_workspace.laws[0].id, var.log_analytics_workspace.id)
tags = merge(var.container_app_environment_tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "84c636e61a6658060893c04d1fcd8cec5b96bb6e"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-11-29 00:14:33"
avm_git_org = "Azure"
avm_git_repo = "terraform-azure-container-apps"
avm_yor_name = "container_env"
avm_yor_trace = "e60e03e2-2ce2-40a4-8f75-b0ebfbbbcbf5"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
lifecycle {
precondition {
condition = var.container_app_environment_internal_load_balancer_enabled == null || var.container_app_environment_infrastructure_subnet_id != null
error_message = "`var.container_app_environment_internal_load_balancer_enabled` can only be set when `var.container_app_environment_infrastructure_subnet_id` is specified."
}
}
}
resource "azurerm_container_app_environment_dapr_component" "dapr" {
for_each = var.dapr_component
component_type = each.value.component_type
container_app_environment_id = local.container_app_environment_id
name = each.value.name
version = each.value.version
ignore_errors = each.value.ignore_errors
init_timeout = each.value.init_timeout
scopes = each.value.scopes
dynamic "metadata" {
for_each = each.value.metadata == null ? [] : each.value.metadata
content {
name = metadata.value.name
secret_name = metadata.value.secret_name
value = metadata.value.value
}
}
dynamic "secret" {
for_each = nonsensitive(toset([for pair in lookup(var.dapr_component_secrets, each.key, []) : pair.name]))
content {
name = secret.key
value = local.dapr_component_secrets[each.key][secret.key]
}
}
}
resource "azurerm_container_app_environment_storage" "storage" {
for_each = var.env_storage
access_key = var.environment_storage_access_key[each.key]
access_mode = each.value.access_mode
account_name = each.value.account_name
container_app_environment_id = local.container_app_environment_id
name = each.value.name
share_name = each.value.share_name
}
resource "azurerm_container_app" "container_app" {
for_each = var.container_apps
container_app_environment_id = local.container_app_environment_id
name = each.value.name
resource_group_name = var.resource_group_name
revision_mode = each.value.revision_mode
tags = merge(each.value.tags, (/*<box>*/ (var.tracing_tags_enabled ? { for k, v in /*</box>*/ {
avm_git_commit = "7003c390bef2e3f8b772b959474e6f7c26fb467e"
avm_git_file = "main.tf"
avm_git_last_modified_at = "2023-11-28 21:02:21"
avm_git_org = "Azure"
avm_git_repo = "terraform-azure-container-apps"
avm_yor_name = "container_app"
avm_yor_trace = "6124aae8-188a-4fbd-8e35-0b7d9eb77ad3"
} /*<box>*/ : replace(k, "avm_", var.tracing_tags_prefix) => v } : {}) /*</box>*/))
workload_profile_name = each.value.workload_profile_name
template {
max_replicas = each.value.template.max_replicas
min_replicas = each.value.template.min_replicas
revision_suffix = each.value.template.revision_suffix
dynamic "container" {
for_each = each.value.template.containers
content {
cpu = container.value.cpu
image = container.value.image
memory = container.value.memory
name = container.value.name
args = container.value.args
command = container.value.command
dynamic "env" {
for_each = container.value.env == null ? [] : container.value.env
content {
name = env.value.name
secret_name = env.value.secret_name
value = env.value.value
}
}
dynamic "liveness_probe" {
for_each = container.value.liveness_probe == null ? [] : [container.value.liveness_probe]
content {
port = liveness_probe.value.port
transport = liveness_probe.value.transport
failure_count_threshold = liveness_probe.value.failure_count_threshold
host = liveness_probe.value.host
initial_delay = liveness_probe.value.initial_delay
interval_seconds = liveness_probe.value.interval_seconds
path = liveness_probe.value.path
timeout = liveness_probe.value.timeout
dynamic "header" {
for_each = liveness_probe.value.header == null ? [] : [liveness_probe.value.header]
content {
name = header.value.name
value = header.value.value
}
}
}
}
dynamic "readiness_probe" {
for_each = container.value.readiness_probe == null ? [] : [container.value.readiness_probe]
content {
port = readiness_probe.value.port
transport = readiness_probe.value.transport
failure_count_threshold = readiness_probe.value.failure_count_threshold
host = readiness_probe.value.host
interval_seconds = readiness_probe.value.interval_seconds
path = readiness_probe.value.path
success_count_threshold = readiness_probe.value.success_count_threshold
timeout = readiness_probe.value.timeout
dynamic "header" {
for_each = readiness_probe.value.header == null ? [] : [readiness_probe.value.header]
content {
name = header.value.name
value = header.value.value
}
}
}
}
dynamic "startup_probe" {
for_each = container.value.startup_probe == null ? [] : [container.value.startup_probe]
content {
port = startup_probe.value.port
transport = startup_probe.value.transport
failure_count_threshold = startup_probe.value.failure_count_threshold
host = startup_probe.value.host
interval_seconds = startup_probe.value.interval_seconds
path = startup_probe.value.path
timeout = startup_probe.value.timeout
dynamic "header" {
for_each = startup_probe.value.header == null ? [] : [startup_probe.value.header]
content {
name = header.value.name
value = header.value.name
}
}
}
}
dynamic "volume_mounts" {
for_each = container.value.volume_mounts == null ? [] : container.value.volume_mounts
content {
name = volume_mounts.value.name
path = volume_mounts.value.path
}
}
}
}
dynamic "custom_scale_rule" {
for_each = each.value.template.custom_scale_rule == null ? [] : each.value.template.custom_scale_rule
content {
custom_rule_type = custom_scale_rule.value.custom_rule_type
metadata = custom_scale_rule.value.metadata
name = custom_scale_rule.value.name
dynamic "authentication" {
for_each = custom_scale_rule.value.authentication == null ? [] : custom_scale_rule.value.authentication
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}
dynamic "http_scale_rule" {
for_each = each.value.template.http_scale_rule == null ? [] : each.value.template.http_scale_rule
content {
concurrent_requests = http_scale_rule.value.concurrent_requests
name = http_scale_rule.value.name
dynamic "authentication" {
for_each = http_scale_rule.value.authentication == null ? [] : http_scale_rule.value.authentication
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}
dynamic "init_container" {
for_each = each.value.template.init_containers == null ? [] : each.value.template.init_containers
content {
image = init_container.value.image
name = init_container.value.name
args = init_container.value.args
command = init_container.value.command
cpu = init_container.value.cpu
memory = init_container.value.memory
dynamic "env" {
for_each = init_container.value.env == null ? [] : init_container.value.env
content {
name = env.value.name
secret_name = env.value.secret_name
value = env.value.value
}
}
dynamic "volume_mounts" {
for_each = init_container.value.volume_mounts == null ? [] : init_container.value.volume_mounts
content {
name = volume_mounts.value.name
path = volume_mounts.value.path
}
}
}
}
dynamic "volume" {
for_each = each.value.template.volume == null ? [] : each.value.template.volume
content {
name = volume.value.name
storage_name = volume.value.storage_name
storage_type = volume.value.storage_type
}
}
}
dynamic "dapr" {
for_each = each.value.dapr == null ? [] : [each.value.dapr]
content {
app_id = dapr.value.app_id
app_port = dapr.value.app_port
app_protocol = dapr.value.app_protocol
}
}
dynamic "identity" {
for_each = each.value.identity == null ? [] : [each.value.identity]
content {
type = identity.value.type
identity_ids = identity.value.identity_ids
}
}
dynamic "ingress" {
for_each = each.value.ingress == null ? [] : [each.value.ingress]
content {
target_port = ingress.value.target_port
allow_insecure_connections = ingress.value.allow_insecure_connections
external_enabled = ingress.value.external_enabled
transport = ingress.value.transport
dynamic "traffic_weight" {
for_each = ingress.value.traffic_weight == null ? [] : [ingress.value.traffic_weight]
content {
percentage = traffic_weight.value.percentage
label = traffic_weight.value.label
latest_revision = traffic_weight.value.latest_revision
revision_suffix = traffic_weight.value.revision_suffix
}
}
dynamic "ip_security_restriction" {
for_each = ingress.value.ip_security_restrictions == null ? [] : ingress.value.ip_security_restrictions
content {
action = ip_security_restriction.value.action
ip_address_range = ip_security_restriction.value.ip_address_range
name = ip_security_restriction.value.name
description = ip_security_restriction.value.description
}
}
}
}
dynamic "registry" {
for_each = each.value.registry == null ? [] : each.value.registry
content {
server = registry.value.server
identity = registry.value.identity
password_secret_name = registry.value.password_secret_name
username = registry.value.username
}
}
dynamic "secret" {
for_each = nonsensitive(toset([for pair in lookup(var.container_app_secrets, each.key, []) : pair.name]))
content {
name = secret.key
identity = local.container_app_secrets[each.key][secret.key].identity
key_vault_secret_id = local.container_app_secrets[each.key][secret.key].key_vault_secret_id
value = local.container_app_secrets[each.key][secret.key].value
}
}
}