mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
3b2282ca57
Fixes #10338 The destruction step for a resource was included the deposed resources for _all_ resources with that name (ignoring the "index"). For example: `aws_instance.foo.0` was including destroying deposed for `aws_instance.foo.1`. This changes the config to the deposed transformer to properly include that index. This change includes a larger change of changing `stateId` to include the index. This affected more parts but was ultimately the issue in question.
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestNodeDestroyResourceDynamicExpand_deposedCount(t *testing.T) {
|
|
var stateLock sync.RWMutex
|
|
state := &State{
|
|
Modules: []*ModuleState{
|
|
&ModuleState{
|
|
Path: rootModulePath,
|
|
Resources: map[string]*ResourceState{
|
|
"aws_instance.bar.0": &ResourceState{
|
|
Type: "aws_instance",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "foo",
|
|
},
|
|
},
|
|
},
|
|
"aws_instance.bar.1": &ResourceState{
|
|
Type: "aws_instance",
|
|
Deposed: []*InstanceState{
|
|
&InstanceState{
|
|
ID: "bar",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
addr, err := parseResourceAddressInternal("aws_instance.bar.0")
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
m := testModule(t, "apply-cbd-count")
|
|
n := &NodeDestroyResource{
|
|
NodeAbstractResource: &NodeAbstractResource{
|
|
Addr: addr,
|
|
ResourceState: state.Modules[0].Resources["aws_instance.bar.0"],
|
|
Config: m.Config().Resources[0],
|
|
},
|
|
}
|
|
|
|
g, err := n.DynamicExpand(&MockEvalContext{
|
|
PathPath: []string{"root"},
|
|
StateState: state,
|
|
StateLock: &stateLock,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.String())
|
|
expected := strings.TrimSpace(`
|
|
aws_instance.bar.0 (deposed #0)
|
|
`)
|
|
if actual != expected {
|
|
t.Fatalf("bad:\n\n%s", actual)
|
|
}
|
|
}
|