forked from Azure/terraform-azurerm-avm-res-app-containerapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
335 lines (287 loc) · 12.1 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
resource "azurerm_container_app" "this" {
container_app_environment_id = var.container_app_environment_resource_id
name = var.name
resource_group_name = var.resource_group_name
revision_mode = var.revision_mode
tags = var.tags
workload_profile_name = var.workload_profile_name
dynamic "template" {
for_each = [var.template]
content {
max_replicas = template.value.max_replicas
min_replicas = template.value.min_replicas
revision_suffix = template.value.revision_suffix
dynamic "container" {
for_each = template.value.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_probes == null ? [] : container.value.liveness_probes
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_probes == null ? [] : container.value.readiness_probes
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.value
}
}
}
}
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 "azure_queue_scale_rule" {
for_each = template.value.azure_queue_scale_rules == null ? [] : template.value.azure_queue_scale_rules
content {
name = azure_queue_scale_rule.value.name
queue_length = azure_queue_scale_rule.value.queue_length
queue_name = azure_queue_scale_rule.value.queue_name
dynamic "authentication" {
for_each = azure_queue_scale_rule.value.authentication
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}
dynamic "custom_scale_rule" {
for_each = template.value.custom_scale_rules == null ? [] : template.value.custom_scale_rules
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 = template.value.http_scale_rules == null ? [] : template.value.http_scale_rules
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 = template.value.init_containers == null ? [] : template.value.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 "tcp_scale_rule" {
for_each = template.value.tcp_scale_rules == null ? [] : template.value.tcp_scale_rules
content {
concurrent_requests = tcp_scale_rule.value.concurrent_requests
name = tcp_scale_rule.value.name
dynamic "authentication" {
for_each = tcp_scale_rule.value.authentication == null ? [] : tcp_scale_rule.value.authentication
content {
secret_name = authentication.value.secret_name
trigger_parameter = authentication.value.trigger_parameter
}
}
}
}
dynamic "volume" {
for_each = template.value.volumes == null ? [] : template.value.volumes
content {
name = volume.value.name
storage_name = volume.value.storage_name
storage_type = volume.value.storage_type
}
}
}
}
dynamic "dapr" {
for_each = var.dapr == null ? [] : [var.dapr]
content {
app_id = dapr.value.app_id
app_port = dapr.value.app_port
app_protocol = dapr.value.app_protocol
}
}
## Resources supporting both SystemAssigned and UserAssigned
dynamic "identity" {
for_each = local.managed_identities.system_assigned_user_assigned
content {
type = identity.value.type
identity_ids = identity.value.user_assigned_resource_ids
}
}
dynamic "ingress" {
for_each = var.ingress == null ? [] : [var.ingress]
content {
target_port = ingress.value.target_port
allow_insecure_connections = ingress.value.allow_insecure_connections
exposed_port = ingress.value.exposed_port
external_enabled = ingress.value.external_enabled
transport = ingress.value.transport
dynamic "traffic_weight" {
for_each = 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_restriction == null ? [] : ingress.value.ip_security_restriction
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 = var.registries == null ? [] : var.registries
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(var.secrets) == null ? {} : nonsensitive(var.secrets)
content {
name = secret.value.name
identity = secret.value.identity
key_vault_secret_id = secret.value.key_vault_secret_id
value = sensitive(secret.value.value)
}
}
dynamic "timeouts" {
for_each = var.container_app_timeouts == null ? [] : [var.container_app_timeouts]
content {
create = timeouts.value.create
delete = timeouts.value.delete
read = timeouts.value.read
update = timeouts.value.update
}
}
}
resource "azurerm_container_app_custom_domain" "this" {
for_each = var.custom_domains
container_app_id = azurerm_container_app.this.id
name = each.value.name
certificate_binding_type = each.value.certificate_binding_type
container_app_environment_certificate_id = each.value.container_app_environment_certificate_id
dynamic "timeouts" {
for_each = each.value.timeouts == null ? [] : [each.value.timeouts]
content {
create = timeouts.value.create
delete = timeouts.value.delete
read = timeouts.value.read
}
}
}
# Example resource implementation
resource "azurerm_management_lock" "this" {
count = var.lock != null ? 1 : 0
lock_level = var.lock.kind
name = coalesce(var.lock.name, "lock-${var.lock.kind}")
scope = azurerm_container_app.this.id
notes = var.lock.kind == "CanNotDelete" ? "Cannot delete the resource or its child resources." : "Cannot delete or modify the resource or its child resources."
}