Skip to content

Commit 6e5f662

Browse files
committed
change the code so it is clearer
1 parent 604edc5 commit 6e5f662

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

governance/third-generation/cloud-agnostic/require-all-modules-have-version-constraint.sentinel

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
# This policy uses the tfconfig/v2 import to require modules to have
22
# version constraint, this is a good practise.
33

4-
# Import common-functions/tfconfig-functions/tfconfig-functions.sentinel
5-
# with alias "config"
6-
import "tfconfig-functions" as config
74

8-
# List of prohibited values
9-
prohibited_list = [""]
5+
import "tfconfig-functions" as config
106

117
# Get all modules
12-
allModulecalls = config.find_all_module_calls()
138

14-
violatingModulecalls = config.filter_attribute_in_list(allModulecalls,
15-
"version_constraint",prohibited_list,false)
9+
allModuleCalls = config.find_all_module_calls()
10+
11+
#Get all module calls tht have version_constraint as undefined or empty.
12+
violatingModuleCalls = filter allModuleCalls as address, mc {
13+
mc.version_constraint else "" is ""
14+
}
1615

1716
# Print any violations
18-
config.print_violations(violatingModulecalls["messages"], "modules")
17+
18+
for violatingModuleCalls as address, mc {
19+
print("Module", address, "does not have version_constraint set")
20+
}
1921

2022
# Main rule
2123
main = rule {
22-
length(violatingModulecalls["messages"]) is 0
24+
length(violatingModuleCalls) is 0
2325
}
2426

2527

governance/third-generation/cloud-agnostic/require-all-providers-have-version-constraint.sentinel

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@
55
# with alias "config"
66
import "tfconfig-functions" as config
77

8-
# List of prohibited provisioners
9-
prohibited_list = [""]
10-
118
# Get all providers
129
allProviders = config.find_all_providers()
1310

14-
violatingProviders = config.filter_attribute_in_list(allProviders,
15-
"version_constraint",prohibited_list,false)
11+
#Get all providers tht has version_constraint as undefined or empty.
12+
violatingProviders = filter allProviders as address, mc {
13+
mc.version_constraint else "" is ""
14+
}
1615

1716
# Print any violations
18-
config.print_violations(violatingProviders["messages"], "Provider")
17+
for violatingProviders as address, mc {
18+
print("Provider", address, "does not have version_constraint set")
19+
}
1920

2021
# Main rule
2122
main = rule {
22-
length(violatingProviders["messages"]) is 0
23+
length(violatingProviders) is 0
2324
}
2425

2526

0 commit comments

Comments
 (0)