mirror of https://github.com/hashicorp/terraform
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.pull/10416/head
parent
3bf93501a1
commit
3b2282ca57
@ -0,0 +1,67 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue