6 "github.com/hashicorp/terraform/addrs"
8 "github.com/hashicorp/hcl2/hcl"
9 "github.com/hashicorp/terraform/configs/configschema"
10 "github.com/zclconf/go-cty/cty"
13 // EvalConfigBlock is an EvalNode implementation that takes a raw
14 // configuration block and evaluates any expressions within it.
16 // ExpandedConfig is populated with the result of expanding any "dynamic"
17 // blocks in the given body, which can be useful for extracting correct source
18 // location information for specific attributes in the result.
19 type EvalConfigBlock struct {
21 Schema *configschema.Block
22 SelfAddr addrs.Referenceable
24 ExpandedConfig *hcl.Body
28 func (n *EvalConfigBlock) Eval(ctx EvalContext) (interface{}, error) {
29 val, body, diags := ctx.EvaluateBlock(*n.Config, n.Schema, n.SelfAddr, EvalDataForNoInstanceKey)
30 if diags.HasErrors() && n.ContinueOnErr {
31 log.Printf("[WARN] Block evaluation failed: %s", diags.Err())
32 return nil, EvalEarlyExitError{}
38 if n.ExpandedConfig != nil {
39 *n.ExpandedConfig = body
42 return nil, diags.ErrWithWarnings()
45 // EvalConfigExpr is an EvalNode implementation that takes a raw configuration
46 // expression and evaluates it.
47 type EvalConfigExpr struct {
49 SelfAddr addrs.Referenceable
53 func (n *EvalConfigExpr) Eval(ctx EvalContext) (interface{}, error) {
54 val, diags := ctx.EvaluateExpr(n.Expr, cty.DynamicPseudoType, n.SelfAddr)
60 return nil, diags.ErrWithWarnings()