filter self references in NodeApplyableResourceIns

Don't save self-references in the state dependencies for a resource.
This commit is contained in:
James Bardin 2018-05-29 17:35:58 -04:00 committed by Martin Atkins
parent ea73922780
commit a5c3c454ab
4 changed files with 28 additions and 11 deletions

View File

@ -411,6 +411,10 @@ func testProvisioner() *MockResourceProvisioner {
Type: cty.String,
Optional: true,
},
"order": {
Type: cty.String,
Optional: true,
},
"when": {
Type: cty.String,
Optional: true,

View File

@ -250,6 +250,20 @@ func (n *NodeAbstractResourceInstance) References() []*addrs.Reference {
return nil
}
// converts an instance address to the legacy dotted notation
func dottedInstanceAddr(tr addrs.ResourceInstance) string {
// For historical reasons, state uses dot-separated instance keys,
// rather than bracketed as in our modern syntax.
var suffix string
switch tk := tr.Key.(type) {
case addrs.IntKey:
suffix = fmt.Sprintf(".%d", int(tk))
case addrs.StringKey:
suffix = fmt.Sprintf(".%s", string(tk))
}
return tr.Resource.String() + suffix
}
// StateReferences returns the dependencies to put into the state for
// this resource.
func (n *NodeAbstractResource) StateReferences() []string {
@ -260,16 +274,7 @@ func (n *NodeAbstractResource) StateReferences() []string {
for _, d := range depsRaw {
switch tr := d.Subject.(type) {
case addrs.ResourceInstance:
// For historical reasons, state uses dot-separated instance keys,
// rather than bracketed as in our modern syntax.
var suffix string
switch tk := tr.Key.(type) {
case addrs.IntKey:
suffix = fmt.Sprintf(".%d", int(tk))
case addrs.StringKey:
suffix = fmt.Sprintf(".%s", string(tk))
}
key := tr.Resource.String() + suffix
key := dottedInstanceAddr(tr)
deps = append(deps, key)
case addrs.Resource:
depStr := tr.String()

View File

@ -77,6 +77,14 @@ func (n *NodeApplyableResourceInstance) EvalTree() EvalNode {
// Determine the dependencies for the state.
stateDeps := n.StateReferences()
// filter out self-references
filtered := []string{}
for _, d := range stateDeps {
if d != dottedInstanceAddr(addr.Resource) {
filtered = append(filtered, d)
}
}
stateDeps = filtered
// Eval info is different depending on what kind of resource this is
switch n.Config.Mode {

View File

@ -4,6 +4,6 @@ resource "aws_instance" "foo" {
provisioner "shell" {
command = "${aws_instance.foo.0.foo}"
order = "${count.index}"
order = "${count.index}"
}
}