Add "expr" type as a schema type #164
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #165
This PR adds the
expr
type as a schema type. Theexpr
type differs from other types in that they do not immediately evaluate a value but instead return an expression structure. For example:string
typeexpr
typeFrom the above, you can see that the expression representation (
var.instance_type
) is returned, not the result of evaluatingvar.instance_type
(t2.micro). Note that attributes such asunknown
are undefined because the expression has not been evaluated.This is useful for writing policies over expression structures. For example, the
expr
type is the only way to handle meta-arguments such asignore_changes
that cannot be evaluated in the normal way.The expression obtained by the
expr
type can be passed to the introducedhcl.expr_list
,hcl.expr_map
, andhcl.expr_call
functions in this PR to perform static analysis of the expression structure. These functions are wrappers around HCL static analysis functions. For example, you can usehcl.expr_list
to check for references inignore_changes
:We have deliberately not introduced functions for static traversal. Perhaps you will need an API like
lang.ReferencesInExpr
, but it is not yet clear what kind of API you will need, so we will consider adding it upon request.