Skip to content

Commit

Permalink
Add a context test for a datasource with count
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Sep 2, 2016
1 parent ca220e3 commit 36c91b4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions terraform/context_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,37 @@ func TestContext2Plan_computedDataResource(t *testing.T) {
}
}

func TestContext2Plan_computedDataCountResource(t *testing.T) {
m := testModule(t, "plan-computed-data-count")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})

plan, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}

if got := len(plan.Diff.Modules); got != 1 {
t.Fatalf("got %d modules; want 1", got)
}

moduleDiff := plan.Diff.Modules[0]

// make sure we created 3 "bar"s
for i := 0; i < 3; i++ {
resource := fmt.Sprintf("data.aws_vpc.bar.%d", i)
if _, ok := moduleDiff.Resources[resource]; !ok {
t.Fatalf("missing diff for %d", i)
}
}
}

// Higher level test at TestResource_dataSourceListPlanPanic
func TestContext2Plan_dataSourceTypeMismatch(t *testing.T) {
m := testModule(t, "plan-data-source-type-mismatch")
Expand Down
9 changes: 9 additions & 0 deletions terraform/test-fixtures/plan-computed-data-count/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "aws_instance" "foo" {
num = "2"
compute = "foo"
}

data "aws_vpc" "bar" {
count = 3
foo = "${aws_instance.foo.foo}"
}

0 comments on commit 36c91b4

Please sign in to comment.