mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
filter self references in NodeApplyableResourceIns
Don't save self-references in the state dependencies for a resource.
This commit is contained in:
parent
ea73922780
commit
a5c3c454ab
@ -411,6 +411,10 @@ func testProvisioner() *MockResourceProvisioner {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"order": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
},
|
||||
"when": {
|
||||
Type: cty.String,
|
||||
Optional: true,
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -4,6 +4,6 @@ resource "aws_instance" "foo" {
|
||||
|
||||
provisioner "shell" {
|
||||
command = "${aws_instance.foo.0.foo}"
|
||||
order = "${count.index}"
|
||||
order = "${count.index}"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user