Policy based on variable value #142
-
Hi :) Currently i am working on a policy which will check the value of a variable. Just like the validation block of terraform/opentofu variable. The policy would be helpful to have a central place for this kind of validation. But for now... im not able to find the correct syntax. I understood, that i have to use the function terraform.variables(). But how can i access the value of a specific variable? For example, how can i get the value of a variable called location: Thanks! I really appreciate all the work you are doing here! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi janno! Thank you for your contributions to the Azure ruleset.
Are you talking about input variables or local values? In the former case you can use |
Beta Was this translation helpful? Give feedback.
You can't do this directly.
variable
block to check if thedefault
is an allowed value. You can't get variable values.terraform.providers
to find yourazurerm
provider and assert itslocation
attribute.This is not so much an OPA thing as how rules work in general. You'd find the same behavior in the normal Go rulesets too. TFLint has a
-var
flag among other options. And then it handles creating the evaluation context including any variables, which rules use to evaluate attribute expressions that they want to assert on. Rules never get to "see" variable val…