Description
See also terraform-linters/tflint-ruleset-terraform#199
Sometimes a ruleset developer wants to walk every expression and evaluate it. This can be easily achieved using the WalkExpressions
and EvaluateExpr
APIs.
However, some expressions depend on the context around them, and this approach can cause errors when evaluated. Some examples that are currently known are:
- for Expressions
- Because a for expression has its own scope, the expression inside may not be uniquely determined unless the for expression is expanded. For example, it is not possible to evaluate only
"value is ${x}"
infor x in [1, 2]: "value is ${x}"
.
- Because a for expression has its own scope, the expression inside may not be uniquely determined unless the for expression is expanded. For example, it is not possible to evaluate only
- ignore_changes
- The
ignore_changes
cannot be evaluated because it is a special reference that is different from other expressions. Something similar is the provider reference.
- The
There are other expressions that are not statically determined, such as self
references and count
/each
, but these are already treated as unknown by TFLint, so no error occurs. Only references that do not contain periods, such as x
and tags
(in other words, references that are not treated as valid by ReferencesInExpr
), will cause an error.
The simplest solution would be to just treat any reference that does not contain a period as an unknown value, but this has the problem of being too permissive compared to the Terraform language evaluation system, since this is an expression that should result in an error in a typical expression evaluation context.
Anyway, somehow we eliminate these unevaluable expression patterns and make all partial expression evaluation possible.