diff --git a/terraform/context_test.go b/terraform/context_test.go index b11234b5b7..0b0ef9b46a 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -411,6 +411,10 @@ func testProvisioner() *MockResourceProvisioner { Type: cty.String, Optional: true, }, + "order": { + Type: cty.String, + Optional: true, + }, "when": { Type: cty.String, Optional: true, diff --git a/terraform/node_resource_abstract.go b/terraform/node_resource_abstract.go index 9021d87577..c4cd92514d 100644 --- a/terraform/node_resource_abstract.go +++ b/terraform/node_resource_abstract.go @@ -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() diff --git a/terraform/node_resource_apply.go b/terraform/node_resource_apply.go index a5fa5037d9..b0d71c715c 100644 --- a/terraform/node_resource_apply.go +++ b/terraform/node_resource_apply.go @@ -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 { diff --git a/terraform/test-fixtures/apply-provisioner-multi-self-ref-single/main.tf b/terraform/test-fixtures/apply-provisioner-multi-self-ref-single/main.tf index d033651b12..9e0cee5e1d 100644 --- a/terraform/test-fixtures/apply-provisioner-multi-self-ref-single/main.tf +++ b/terraform/test-fixtures/apply-provisioner-multi-self-ref-single/main.tf @@ -4,6 +4,6 @@ resource "aws_instance" "foo" { provisioner "shell" { command = "${aws_instance.foo.0.foo}" - order = "${count.index}" + order = "${count.index}" } }