Skip to content

Commit 4167314

Browse files
authored
Merge pull request hashicorp#306 from hashicorp/multiple-orgs-in-pmr-policy
multiple orgs in require-all-resources-from-pmr.sentinel
2 parents 37293b1 + 4c50519 commit 4167314

File tree

7 files changed

+54
-16
lines changed

7 files changed

+54
-16
lines changed

governance/third-generation/cloud-agnostic/require-all-resources-from-pmr.sentinel

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ import "strings"
1414
### Parameters ###
1515
# The address of the TFC or TFE server
1616
param address default "app.terraform.io"
17-
# The organization on the TFC or TFE server
18-
param organization
17+
# The organizations on the TFC or TFE server that modules can some from
18+
param organizations
1919

2020
# Fnd modules called from root module that are not in the desired PMR
2121
violatingMCs = filter tfconfig.module_calls as index, mc {
2222
mc.module_address is "" and
23-
not strings.has_prefix(mc.source, address + "/" + organization)
23+
not any organizations as organization {
24+
strings.has_prefix(mc.source, address + "/" + organization)
25+
}
2426
}
2527

2628
# Print violation messages for invalid modules
2729
if length(violatingMCs) > 0 and not tfrun.is_destroy {
28-
print("All modules called from the root module must come from the",
29-
"private module registry", address + "/" + organization)
30+
print("All modules called from the root module must come from a",
31+
"private module registry in one of these organizations:", organizations, " on server", address)
3032
for violatingMCs as address, mc {
3133
print("The module", mc.name, "called from the root module has source",
3234
mc.source)

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/fail.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ param "address" {
22
value = "app.terraform.io"
33
}
44

5-
param "organization" {
6-
value = "Cloud-Operations"
5+
param "organizations" {
6+
value = ["Cloud-Operations", "App-Operations"]
77
}
88

99
mock "tfconfig/v2" {

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/mock-tfconfig-fail.sentinel

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,33 @@ outputs = {
184184
}
185185

186186
module_calls = {
187-
"nested": {
187+
"nested-local": {
188188
"config": {},
189189
"count": {},
190190
"for_each": {},
191191
"module_address": "",
192-
"name": "nested",
192+
"name": "nested-local",
193193
"source": "./module",
194194
"version_constraint": "",
195195
},
196+
"nested-pmr": {
197+
"config": {},
198+
"count": {},
199+
"for_each": {},
200+
"module_address": "",
201+
"name": "nested-pmr",
202+
"source": "app.terraform.io/Operations/compute/aws",
203+
"version_constraint": "",
204+
},
205+
"nested-public-registry": {
206+
"config": {},
207+
"count": {},
208+
"for_each": {},
209+
"module_address": "",
210+
"name": "nested-public-registry",
211+
"source": "terraform-aws-modules/compute/aws",
212+
"version_constraint": "",
213+
},
196214
}
197215

198216
strip_index = func(addr) {

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/mock-tfconfig-pass-destroy.sentinel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ module_calls = {
122122
"source": "app.terraform.io/Cloud-Operations/compute/aws",
123123
"version_constraint": "",
124124
},
125+
"nested-local": {
126+
"config": {},
127+
"count": {},
128+
"for_each": {},
129+
"module_address": "",
130+
"name": "nested-local",
131+
"source": "./module",
132+
"version_constraint": "",
133+
},
125134
}
126135

127136
strip_index = func(addr) {

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/mock-tfconfig-pass.sentinel

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,22 @@ outputs = {
113113
}
114114

115115
module_calls = {
116-
"nested": {
116+
"nested-cloud": {
117117
"config": {},
118118
"count": {},
119119
"for_each": {},
120120
"module_address": "",
121-
"name": "nested",
122-
"source": "app.terraform.io/Cloud-Operations/compute/aws",
121+
"name": "nested-cloud",
122+
"source": "app.terraform.io/Cloud-Operations/network/aws",
123+
"version_constraint": "",
124+
},
125+
"nested-app": {
126+
"config": {},
127+
"count": {},
128+
"for_each": {},
129+
"module_address": "",
130+
"name": "nested-app",
131+
"source": "app.terraform.io/App-Operations/compute/aws",
123132
"version_constraint": "",
124133
},
125134
}

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/pass-destroy.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ param "address" {
22
value = "app.terraform.io"
33
}
44

5-
param "organization" {
6-
value = "Cloud-Operations"
5+
param "organizations" {
6+
value = ["Cloud-Operations", "App-Operations"]
77
}
88

99
mock "tfconfig/v2" {

governance/third-generation/cloud-agnostic/test/require-all-resources-from-pmr/pass.hcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ param "address" {
22
value = "app.terraform.io"
33
}
44

5-
param "organization" {
6-
value = "Cloud-Operations"
5+
param "organizations" {
6+
value = ["Cloud-Operations", "App-Operations"]
77
}
88

99
mock "tfconfig/v2" {

0 commit comments

Comments
 (0)