Support using self in the provisioner of resources that use for_each
This commit is contained in:
parent
112b7755c0
commit
b9af3cd86b
|
@ -117,6 +117,7 @@ type EvalValidateProvisioner struct {
|
||||||
Schema **configschema.Block
|
Schema **configschema.Block
|
||||||
Config *configs.Provisioner
|
Config *configs.Provisioner
|
||||||
ResourceHasCount bool
|
ResourceHasCount bool
|
||||||
|
ResourceHasForEach bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalValidateProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalValidateProvisioner) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
|
@ -198,6 +199,19 @@ func (n *EvalValidateProvisioner) evaluateBlock(ctx EvalContext, body hcl.Body,
|
||||||
// expected type since none of these elements are known at this
|
// expected type since none of these elements are known at this
|
||||||
// point anyway.
|
// point anyway.
|
||||||
selfAddr = n.ResourceAddr.Instance(addrs.IntKey(0))
|
selfAddr = n.ResourceAddr.Instance(addrs.IntKey(0))
|
||||||
|
} else if n.ResourceHasForEach {
|
||||||
|
// For a resource that has for_each, we allow each.value and each.key
|
||||||
|
// but don't know at this stage what it will return.
|
||||||
|
keyData = InstanceKeyEvalData{
|
||||||
|
EachKey: cty.UnknownVal(cty.String),
|
||||||
|
EachValue: cty.DynamicVal,
|
||||||
|
}
|
||||||
|
|
||||||
|
// "self" can't point to an unknown key, but we'll force it to be
|
||||||
|
// key "" here, which should return an unknown value of the
|
||||||
|
// expected type since none of these elements are known at
|
||||||
|
// this point anyway.
|
||||||
|
selfAddr = n.ResourceAddr.Instance(addrs.StringKey(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.EvaluateBlock(body, schema, selfAddr, keyData)
|
return ctx.EvaluateBlock(body, schema, selfAddr, keyData)
|
||||||
|
|
|
@ -54,6 +54,7 @@ func (n *NodeValidatableResource) EvalTree() EvalNode {
|
||||||
|
|
||||||
if managed := n.Config.Managed; managed != nil {
|
if managed := n.Config.Managed; managed != nil {
|
||||||
hasCount := n.Config.Count != nil
|
hasCount := n.Config.Count != nil
|
||||||
|
hasForEach := n.Config.ForEach != nil
|
||||||
|
|
||||||
// Validate all the provisioners
|
// Validate all the provisioners
|
||||||
for _, p := range managed.Provisioners {
|
for _, p := range managed.Provisioners {
|
||||||
|
@ -79,6 +80,7 @@ func (n *NodeValidatableResource) EvalTree() EvalNode {
|
||||||
Schema: &provisionerSchema,
|
Schema: &provisionerSchema,
|
||||||
Config: p,
|
Config: p,
|
||||||
ResourceHasCount: hasCount,
|
ResourceHasCount: hasCount,
|
||||||
|
ResourceHasForEach: hasForEach,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue