-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
33 lines (30 loc) · 1.26 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
provider "azurerm" {
features {}
alias = "policy"
subscription_id = var.subscription_id
client_id = var.client_id
client_secret = var.client_secret
tenant_id = var.tenant_id
}
resource "azurerm_policy_definition" "main" {
for_each = { for policy in fileset("${path.module}/policies", "*.json") : policy => jsondecode(file("${path.module}/policies/${policy}")) }
name = "${var.base_name}_${split(".", each.key)[0]}"
display_name = try(each.value.display_name, "Custom Policy")
policy_type = try(each.value.policy_type, "Custom")
mode = try(each.value.mode, "All")
policy_rule = jsonencode(each.value.properties.policyRule)
parameters = jsonencode(each.value.properties.parameters)
metadata = jsonencode(each.value.properties.metadata)
management_group_id = var.management_group_id
provider = azurerm.policy
}
resource "azurerm_management_group_policy_assignment" "main" {
for_each = azurerm_policy_definition.main
name = substr(split(".", each.value.name)[0], 0, 24)
policy_definition_id = each.value.id
management_group_id = var.management_group_id
depends_on = [
azurerm_policy_definition.main
]
provider = azurerm.policy
}