Skip to content

Commit 13bef79

Browse files
authored
2.9.1 (#102)
1 parent 5edec4f commit 13bef79

File tree

8 files changed

+34
-37
lines changed

8 files changed

+34
-37
lines changed

README.md

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,12 @@
3737

3838
```bash
3939
📦examples
40-
├──📜assignments_mg.tf
41-
├──📜backend.tf
42-
├──📜built-in.tf
43-
├──📜data.tf
44-
├──📜definitions.tf
45-
├──📜exemptions.tf
46-
├──📜initiatives.tf
47-
├──📜variables.tf
4840
📦modules
4941
└──📂def_assignment
50-
├──📜main.tf
51-
├──📜outputs.tf
52-
└──📜variables.tf
5342
└──📂definition
54-
├──📜main.tf
55-
├──📜outputs.tf
56-
└──📜variables.tf
5743
└──📂exemption
58-
├──📜main.tf
59-
├──📜outputs.tf
60-
└──📜variables.tf
6144
└──📂initiative
62-
├──📜main.tf
63-
├──📜outputs.tf
64-
└──📜variables.tf
6545
└──📂set_assignment
66-
├──📜main.tf
67-
├──📜outputs.tf
68-
└──📜variables.tf
6946
📦policies
7047
└──📂policy_category (e.g. General, should correspond to [var.policy_category])
7148
└──📜policy_name.json (e.g. whitelist_regions, should correspond to [var.policy_name])
@@ -162,10 +139,7 @@ module org_mg_platform_diagnostics_initiative {
162139
data.azurerm_management_group.team_a.id
163140
]
164141
165-
non_compliance_messages = {
166-
null = "The Default non-compliance message for all member definitions"
167-
DeployApplicationGatewayDiagnosticSetting = "The non-compliance message for the deploy_application_gateway_diagnostic_setting definition"
168-
}
142+
non_compliance_messages = module.platform_diagnostics_initiative.non_compliance_messages
169143
}
170144
```
171145

examples/initiatives.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module "configure_asc_initiative" {
77
initiative_display_name = "[Security]: Configure Azure Security Center"
88
initiative_description = "Deploys and configures Azure Security Center settings and defines exports"
99
initiative_category = "Security Center"
10+
initiative_version = "2.0.0"
1011
management_group_id = data.azurerm_management_group.org.id
1112

1213
# Populate member_definitions

modules/exemption/variables.tf

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
variable "name" {
22
type = string
33
description = "Name for the Policy Exemption"
4+
5+
validation {
6+
condition = length(var.name) <= 64
7+
error_message = "Exemption names have a maximum 64 character limit."
8+
}
49
}
510

611
variable "display_name" {
712
type = string
813
description = "Display name for the Policy Exemption"
14+
15+
validation {
16+
condition = length(var.display_name) <= 128
17+
error_message = "Exemption display names have a maximum 128 character limit."
18+
}
919
}
1020

1121
variable "description" {
1222
type = string
1323
description = "Description for the Policy Exemption"
24+
25+
validation {
26+
condition = length(var.description) <= 512
27+
error_message = "Exemption descriptions have a maximum 512 character limit."
28+
}
1429
}
1530

1631
variable "scope" {
@@ -72,7 +87,7 @@ locals {
7287

7388
# generate reference Ids when unknown, assumes the set was created with the initiative module
7489
policy_definition_reference_ids = length(var.member_definition_names) > 0 ? [for name in var.member_definition_names :
75-
replace(substr(title(replace(name, "/-|_|\\s/", " ")), 0, 64), "/\\s/", "")
90+
replace(title(replace(name, "/-|_|\\s/", " ")), "/\\s/", "")
7691
] : var.policy_definition_reference_ids
7792

7893
exemption_id = try(

modules/initiative/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module guest_config_prereqs_initiative {
134134
| initiative_name | Policy initiative name. Changing this forces a new resource to be created | `string` | n/a | yes |
135135
| initiative_version | The version for this initiative, defaults to 1.0.0 | `string` | `"1.0.0"` | no |
136136
| management_group_id | The management group scope at which the initiative will be defined. Defaults to current Subscription if omitted. Changing this forces a new resource to be created. Note: if you are using azurerm_management_group to assign a value to management_group_id, be sure to use name or group_id attribute, but not id. | `string` | `null` | no |
137-
| member_definitions | Policy Definition resource nodes that will be members of this initiative | `list(any)` | n/a | yes |
137+
| member_definitions | Policy Definition resource nodes that will be members of this initiative | `any` | n/a | yes |
138138
| merge_effects | Should the module merge all member definition effects? Defaults to true | `bool` | `true` | no |
139139
| merge_parameters | Should the module merge all member definition parameters? Defaults to true | `bool` | `true` | no |
140140

modules/initiative/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "terraform_data" "set_replace" {
2-
input = md5(jsonencode(local.parameters))
2+
input = local.replace_trigger
33
}
44

55
resource "azurerm_policy_set_definition" "set" {

modules/initiative/outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ output "initiative" {
4141
policy_definition_reference = azurerm_policy_set_definition.set.policy_definition_reference
4242
reference_ids = try(azurerm_policy_set_definition.set.policy_definition_reference.*.reference_id, [])
4343
role_definition_ids = local.all_role_definition_ids
44+
replace_trigger = local.replace_trigger
4445
}
4546
}

modules/initiative/variables.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ variable "initiative_version" {
4848
}
4949

5050
variable "member_definitions" {
51-
type = list(any)
51+
type = any
5252
description = "Policy Definition resource nodes that will be members of this initiative"
5353
}
5454

@@ -77,17 +77,20 @@ variable "duplicate_members" {
7777
}
7878

7979
locals {
80-
# colate all definition properties into a single reusable object
81-
# index numbers (idx) will be prefixed to references when using duplicate member definitions
80+
# colate all definition properties into a single reusable object:
81+
# - definition references take their policy name transformed to upper camel case
82+
# - index numbers (idx) will be prefixed to references when using duplicate member definitions
8283
member_properties = {
8384
for idx, d in var.member_definitions :
8485
var.duplicate_members == false ? d.name : "${idx}_${d.name}" => {
8586
id = d.id
86-
reference = var.duplicate_members == false ? "${replace(substr(title(replace(d.name, "/-|_|\\s/", " ")), 0, 64), "/\\s/", "")}" : "${idx}_${replace(substr(title(replace(d.name, "/-|_|\\s/", " ")), 0, 61), "/\\s/", "")}"
87-
parameters = coalesce(null, jsondecode(d.parameters), null)
8887
mode = try(d.mode, "")
89-
role_definition_ids = try(jsondecode(d.policy_rule).then.details.roleDefinitionIds, [])
88+
reference = var.duplicate_members == false ? replace(title(replace(d.name, "/-|_|\\s/", " ")), "/\\s/", "") : "${idx}_${replace(title(replace(d.name, "/-|_|\\s/", " ")), "/\\s/", "")}"
89+
parameters = coalesce(null, jsondecode(d.parameters), null)
90+
category = try(jsondecode(d.metadata).category, "")
91+
version = try(jsondecode(d.metadata).version, "1.*.*")
9092
non_compliance_message = try(jsondecode(d.metadata).non_compliance_message, d.description, d.display_name, "Flagged by Policy: ${d.name}")
93+
role_definition_ids = try(jsondecode(d.policy_rule).then.details.roleDefinitionIds, [])
9194
}
9295
}
9396

@@ -112,6 +115,9 @@ locals {
112115
}
113116
})...)
114117

118+
# generate replacement trigger by hashing parameters, included as an output to prevent regen at assignment
119+
replace_trigger = md5(jsonencode(local.parameters))
120+
115121
# combine all role definition IDs present in the policyRule
116122
all_role_definition_ids = try(distinct([for v in flatten(values({
117123
for k, v in local.member_properties :

modules/set_assignment/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "terraform_data" "set_assign_replace" {
2-
input = md5(jsonencode(var.initiative.parameters))
2+
input = try(var.initiative.replace_trigger, md5(jsonencode(var.initiative.parameters)))
33
}
44

55
resource "azurerm_management_group_policy_assignment" "set" {

0 commit comments

Comments
 (0)