diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/eval_validate.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/eval_validate.go | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/eval_validate.go b/vendor/github.com/hashicorp/terraform/terraform/eval_validate.go index 0033e01..6b809a2 100644 --- a/vendor/github.com/hashicorp/terraform/terraform/eval_validate.go +++ b/vendor/github.com/hashicorp/terraform/terraform/eval_validate.go | |||
@@ -112,11 +112,12 @@ func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) { | |||
112 | // the configuration of a provisioner belonging to a resource. The provisioner | 112 | // the configuration of a provisioner belonging to a resource. The provisioner |
113 | // config is expected to contain the merged connection configurations. | 113 | // config is expected to contain the merged connection configurations. |
114 | type EvalValidateProvisioner struct { | 114 | type EvalValidateProvisioner struct { |
115 | ResourceAddr addrs.Resource | 115 | ResourceAddr addrs.Resource |
116 | Provisioner *provisioners.Interface | 116 | Provisioner *provisioners.Interface |
117 | Schema **configschema.Block | 117 | Schema **configschema.Block |
118 | Config *configs.Provisioner | 118 | Config *configs.Provisioner |
119 | ResourceHasCount bool | 119 | ResourceHasCount bool |
120 | ResourceHasForEach bool | ||
120 | } | 121 | } |
121 | 122 | ||
122 | func (n *EvalValidateProvisioner) Eval(ctx EvalContext) (interface{}, error) { | 123 | func (n *EvalValidateProvisioner) Eval(ctx EvalContext) (interface{}, error) { |
@@ -198,6 +199,19 @@ func (n *EvalValidateProvisioner) evaluateBlock(ctx EvalContext, body hcl.Body, | |||
198 | // expected type since none of these elements are known at this | 199 | // expected type since none of these elements are known at this |
199 | // point anyway. | 200 | // point anyway. |
200 | selfAddr = n.ResourceAddr.Instance(addrs.IntKey(0)) | 201 | selfAddr = n.ResourceAddr.Instance(addrs.IntKey(0)) |
202 | } else if n.ResourceHasForEach { | ||
203 | // For a resource that has for_each, we allow each.value and each.key | ||
204 | // but don't know at this stage what it will return. | ||
205 | keyData = InstanceKeyEvalData{ | ||
206 | EachKey: cty.UnknownVal(cty.String), | ||
207 | EachValue: cty.DynamicVal, | ||
208 | } | ||
209 | |||
210 | // "self" can't point to an unknown key, but we'll force it to be | ||
211 | // key "" here, which should return an unknown value of the | ||
212 | // expected type since none of these elements are known at | ||
213 | // this point anyway. | ||
214 | selfAddr = n.ResourceAddr.Instance(addrs.StringKey("")) | ||
201 | } | 215 | } |
202 | 216 | ||
203 | return ctx.EvaluateBlock(body, schema, selfAddr, keyData) | 217 | return ctx.EvaluateBlock(body, schema, selfAddr, keyData) |
@@ -370,10 +384,21 @@ func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) { | |||
370 | diags = diags.Append(countDiags) | 384 | diags = diags.Append(countDiags) |
371 | } | 385 | } |
372 | 386 | ||
387 | if n.Config.ForEach != nil { | ||
388 | keyData = InstanceKeyEvalData{ | ||
389 | EachKey: cty.UnknownVal(cty.String), | ||
390 | EachValue: cty.UnknownVal(cty.DynamicPseudoType), | ||
391 | } | ||
392 | |||
393 | // Evaluate the for_each expression here so we can expose the diagnostics | ||
394 | forEachDiags := n.validateForEach(ctx, n.Config.ForEach) | ||
395 | diags = diags.Append(forEachDiags) | ||
396 | } | ||
397 | |||
373 | for _, traversal := range n.Config.DependsOn { | 398 | for _, traversal := range n.Config.DependsOn { |
374 | ref, refDiags := addrs.ParseRef(traversal) | 399 | ref, refDiags := addrs.ParseRef(traversal) |
375 | diags = diags.Append(refDiags) | 400 | diags = diags.Append(refDiags) |
376 | if len(ref.Remaining) != 0 { | 401 | if !refDiags.HasErrors() && len(ref.Remaining) != 0 { |
377 | diags = diags.Append(&hcl.Diagnostic{ | 402 | diags = diags.Append(&hcl.Diagnostic{ |
378 | Severity: hcl.DiagError, | 403 | Severity: hcl.DiagError, |
379 | Summary: "Invalid depends_on reference", | 404 | Summary: "Invalid depends_on reference", |
@@ -542,3 +567,18 @@ func (n *EvalValidateResource) validateCount(ctx EvalContext, expr hcl.Expressio | |||
542 | 567 | ||
543 | return diags | 568 | return diags |
544 | } | 569 | } |
570 | |||
571 | func (n *EvalValidateResource) validateForEach(ctx EvalContext, expr hcl.Expression) (diags tfdiags.Diagnostics) { | ||
572 | _, known, forEachDiags := evaluateResourceForEachExpressionKnown(expr, ctx) | ||
573 | // If the value isn't known then that's the best we can do for now, but | ||
574 | // we'll check more thoroughly during the plan walk | ||
575 | if !known { | ||
576 | return diags | ||
577 | } | ||
578 | |||
579 | if forEachDiags.HasErrors() { | ||
580 | diags = diags.Append(forEachDiags) | ||
581 | } | ||
582 | |||
583 | return diags | ||
584 | } | ||