-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.containers.tf
52 lines (45 loc) · 2.28 KB
/
main.containers.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
# This uses azapi in order to avoid having to grant data plane permissions
resource "azapi_resource" "containers" {
for_each = var.containers
type = "Microsoft.Storage/storageAccounts/blobServices/containers@2022-09-01"
body = jsonencode({
properties = {
metadata = each.value.metadata
publicAccess = each.value.public_access
}
})
name = each.value.name
parent_id = "${azurerm_storage_account.this.id}/blobServices/default"
dynamic "timeouts" {
for_each = each.value.timeouts == null ? [] : [each.value.timeouts]
content {
create = timeouts.value.create
delete = timeouts.value.delete
read = timeouts.value.read
update = timeouts.value.update
}
}
}
# Enable role assignments for containers
resource "azurerm_role_assignment" "containers" {
for_each = local.containers_role_assignments
principal_id = each.value.role_assignment.principal_id
scope = azapi_resource.containers[each.value.container_key].id
condition = each.value.role_assignment.condition
condition_version = each.value.role_assignment.condition_version
delegated_managed_identity_resource_id = each.value.role_assignment.delegated_managed_identity_resource_id
role_definition_id = strcontains(lower(each.value.role_assignment.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? each.value.role_assignment.role_definition_id_or_name : null
role_definition_name = strcontains(lower(each.value.role_assignment.role_definition_id_or_name), lower(local.role_definition_resource_substring)) ? null : each.value.role_assignment.role_definition_id_or_name
skip_service_principal_aad_check = each.value.role_assignment.skip_service_principal_aad_check
}
resource "time_sleep" "wait_for_rbac_before_container_operations" {
count = length(var.role_assignments) > 0 && length(var.containers) > 0 ? 1 : 0
create_duration = var.wait_for_rbac_before_container_operations.create
destroy_duration = var.wait_for_rbac_before_container_operations.destroy
triggers = {
role_assignments = jsonencode(var.role_assignments)
}
depends_on = [
azurerm_role_assignment.storage_account
]
}