Skip to content

Policy based on variable value #142

Closed Answered by bendrucker
JannoTjarks asked this question in Q&A
Discussion options

You must be logged in to vote

Now I want to check, if the input is...

You can't do this directly.

  1. You can get the variable block to check if the default is an allowed value. You can't get variable values.
  2. You can also check some block that references this variable. You can use terraform.providers to find your azurerm provider and assert its location 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…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JannoTjarks
Comment options

@bendrucker
Comment options

Answer selected by JannoTjarks
@JannoTjarks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #141 on March 14, 2025 09:57.