Skip to content

Commit 88ac1b0

Browse files
committed
terraform: another test for count index
1 parent ea18b62 commit 88ac1b0

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

terraform/context_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,29 @@ func TestContextPlan_countIndex(t *testing.T) {
24872487
}
24882488
}
24892489

2490+
func TestContextPlan_countIndexZero(t *testing.T) {
2491+
m := testModule(t, "plan-count-index-zero")
2492+
p := testProvider("aws")
2493+
p.DiffFn = testDiffFn
2494+
ctx := testContext(t, &ContextOpts{
2495+
Module: m,
2496+
Providers: map[string]ResourceProviderFactory{
2497+
"aws": testProviderFuncFixed(p),
2498+
},
2499+
})
2500+
2501+
plan, err := ctx.Plan(nil)
2502+
if err != nil {
2503+
t.Fatalf("err: %s", err)
2504+
}
2505+
2506+
actual := strings.TrimSpace(plan.String())
2507+
expected := strings.TrimSpace(testTerraformPlanCountIndexZeroStr)
2508+
if actual != expected {
2509+
t.Fatalf("bad:\n%s", actual)
2510+
}
2511+
}
2512+
24902513
func TestContextPlan_countVar(t *testing.T) {
24912514
m := testModule(t, "plan-count-var")
24922515
p := testProvider("aws")

terraform/terraform_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,18 @@ STATE:
492492
<no state>
493493
`
494494

495+
const testTerraformPlanCountIndexZeroStr = `
496+
DIFF:
497+
498+
CREATE: aws_instance.foo
499+
foo: "" => "0"
500+
type: "" => "aws_instance"
501+
502+
STATE:
503+
504+
<no state>
505+
`
506+
495507
const testTerraformPlanCountOneIndexStr = `
496508
DIFF:
497509
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resource "aws_instance" "foo" {
2+
foo = "${count.index}"
3+
}

0 commit comments

Comments
 (0)