Skip to content

Partial expression evaluation #339

Open
@wata727

Description

@wata727

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}" in for x in [1, 2]: "value is ${x}".
  • 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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions