2018-01-21 23:29:43 +00:00
|
|
|
package dynblock
|
|
|
|
|
|
|
|
import (
|
2019-09-09 23:08:19 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2018-01-21 23:29:43 +00:00
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
type exprWrap struct {
|
|
|
|
hcl.Expression
|
|
|
|
i *iteration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e exprWrap) Variables() []hcl.Traversal {
|
|
|
|
raw := e.Expression.Variables()
|
|
|
|
ret := make([]hcl.Traversal, 0, len(raw))
|
|
|
|
|
|
|
|
// Filter out traversals that refer to our iterator name or any
|
|
|
|
// iterator we've inherited; we're going to provide those in
|
|
|
|
// our Value wrapper, so the caller doesn't need to know about them.
|
|
|
|
for _, traversal := range raw {
|
|
|
|
rootName := traversal.RootName()
|
|
|
|
if rootName == e.i.IteratorName {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, inherited := e.i.Inherited[rootName]; inherited {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ret = append(ret, traversal)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e exprWrap) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
|
|
|
|
extCtx := e.i.EvalContext(ctx)
|
|
|
|
return e.Expression.Value(extCtx)
|
|
|
|
}
|
|
|
|
|
2018-01-27 17:03:44 +00:00
|
|
|
// UnwrapExpression returns the expression being wrapped by this instance.
|
|
|
|
// This allows the original expression to be recovered by hcl.UnwrapExpression.
|
|
|
|
func (e exprWrap) UnwrapExpression() hcl.Expression {
|
|
|
|
return e.Expression
|
2018-01-21 23:29:43 +00:00
|
|
|
}
|