-
Notifications
You must be signed in to change notification settings - Fork 109
More help requested! accessing configuration_modules within the plan #109
Comments
No worries at all! Yes -- we try to do the heavy lifting, especially when Terraform modules are This is what the However: this currently includes data about the resources themselves. There is a workaround though -- you can circumvent the package rules.my_rule
import data.fugue
# Pull out the module calls and make them look like regular resources
module_call_resources := { name: module_resource |
# Access this through `fugue.plan`
module = fugue.plan.configuration.root_module.module_call_resources[name]
module_resource = {
"id": name,
"_type": "module_call",
"_provider": "aws",
"source": module.source
}
}
# Tells Regula to work on the entire config rather than passing this rule
# a specific resource
resource_type = "MULTIPLE"
# Some list of approved modules
allowed_modules := {
"terraform-aws-modules/lambda/aws",
}
# Check that the module source is in the approved list and allow / deny it
policy[p] {
m = module_call_resources[_]
allowed_modules[m.source]
p = fugue.allow({
"resource": m,
})
} {
m = module_call_resources[_]
not allowed_modules[m.source]
p = fugue.deny({
"resource": m,
"message": sprintf("This module is not in our approved list: %s", [m.source]),
})
} That being said; this is a slight workaround and we will look at presenting this On a different note -- we're currently building a CLI for Regula that still uses |
Hi, Thanks for a very detailed answer! I'll play with that and let you know how I get on. My two immediate use cases for wanting to access this information are:
I'll drop an email and have a play with the CLI, sounds interesting! FYI: We have combined Regula and Conftest, and are utilising this via run atlantis so we have compliance checks built into our PR approval process. With the example above of blocking resource creation, we can then utilise runatlantis's feature of |
I had to change a couple of things in your example, wonder if my version of Regula is behind yours? See commented lines
I've built this out to compare the git ref / tag, as we wanted to enforce a minimum version for our modules (i.e. if we release a new version of a module with a required label, we can now ensure everyone upgrades). It's not clean and I'm sure it can be optimised, but it's getting late on a Friday so it will do for now:
As seen in the TODO, this currently doesn't support child_modules, I've seen some examples in the codebase of using |
This is what I came up with for nested child modules, bit hacky but it will do until (hopefully) this information is available natively via regula :)
|
Awesome, yeah, that looks good! I've added a ticket for making this information more easily available, I'll reach out if we have something working. |
I promise I'll stop asking for help soon.... 😃
I want to use some of the information in the plan to implement some rules that do things like:
configuration.root_module.module_calls
)configuration.resource_changes
)I found you guys are already doing the heavy lifting here but I can't work out how I can actually access these values in a rule?
I'm sure this is down to my lack of knowledge around rego namespaces / imports, so I apologise if this is an obvious question!
The text was updated successfully, but these errors were encountered: