core: Correct test TestOrphanResourceCountTransformer_zeroAndNone
The logic under test has intentionally changed here so that setting count to any value -- even 1 -- causes Terraform to prefer to keep indexed instances if both non-indexed and indexed are present. Previously Terraform treated count = 1 as equivalent to count not set at all, but we now recognize these as two different situations and treat count = 1 as the same as any other non-zero count, to ensure that if count is set conditionally it'll always produce indexed instances, even if the dynamic expression ends up evaluating to 1.
This commit is contained in:
parent
ad6bb4a1d5
commit
8fabcc0c08
|
@ -23,7 +23,6 @@ type OrphanResourceCountTransformer struct {
|
|||
}
|
||||
|
||||
func (t *OrphanResourceCountTransformer) Transform(g *Graph) error {
|
||||
log.Printf("[TRACE] OrphanResourceCount: Starting...")
|
||||
|
||||
// Grab the module in the state just for this resource address
|
||||
ms := t.State.ModuleByPath(t.Addr.Module)
|
||||
|
@ -81,6 +80,7 @@ func (t *OrphanResourceCountTransformer) transformCount(haveKeys map[addrs.Insta
|
|||
if f := t.Concrete; f != nil {
|
||||
node = f(abstract)
|
||||
}
|
||||
log.Printf("[TRACE] OrphanResourceCount(non-zero): adding %s as %T", t.Addr, node)
|
||||
g.Add(node)
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,7 @@ func (t *OrphanResourceCountTransformer) transformZeroCount(haveKeys map[addrs.I
|
|||
if f := t.Concrete; f != nil {
|
||||
node = f(abstract)
|
||||
}
|
||||
log.Printf("[TRACE] OrphanResourceCount(zero): adding %s as %T", t.Addr, node)
|
||||
g.Add(node)
|
||||
}
|
||||
|
||||
|
@ -128,6 +129,7 @@ func (t *OrphanResourceCountTransformer) transformNoCount(haveKeys map[addrs.Ins
|
|||
if f := t.Concrete; f != nil {
|
||||
node = f(abstract)
|
||||
}
|
||||
log.Printf("[TRACE] OrphanResourceCount(no-count): adding %s as %T", t.Addr, node)
|
||||
g.Add(node)
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ func TestOrphanResourceCountTransformer_zeroAndNone(t *testing.T) {
|
|||
{
|
||||
tf := &OrphanResourceCountTransformer{
|
||||
Concrete: testOrphanResourceConcreteFunc,
|
||||
Count: 1,
|
||||
Count: -1,
|
||||
Addr: addrs.RootModuleInstance.Resource(
|
||||
addrs.ManagedResourceMode, "aws_instance", "foo",
|
||||
),
|
||||
|
@ -273,7 +273,7 @@ func TestOrphanResourceCountTransformer_zeroAndNone(t *testing.T) {
|
|||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTransformOrphanResourceCountZeroAndNoneStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue