From dd8ee38ba83dbad2db2742bf0b4d094a934cadef Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 28 Jan 2017 11:09:24 -0800 Subject: [PATCH] providers/test: additional testing via integration tests --- builtin/providers/test/data_source_test.go | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/builtin/providers/test/data_source_test.go b/builtin/providers/test/data_source_test.go index 7a14b58af..3f4e5ada6 100644 --- a/builtin/providers/test/data_source_test.go +++ b/builtin/providers/test/data_source_test.go @@ -2,6 +2,7 @@ package test import ( "errors" + "fmt" "strings" "testing" @@ -55,3 +56,46 @@ resource "test_resource" "foo" { }, }) } + +// Test that the output of a data source can be used as the value for +// a "count" in a real resource. This would fail with "count cannot be computed" +// at some point. +func TestDataSource_valueAsResourceCount(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: func(s *terraform.State) error { + return nil + }, + Steps: []resource.TestStep{ + { + Config: strings.TrimSpace(` +data "test_data_source" "test" { + input = "4" +} + +resource "test_resource" "foo" { + count = "${data.test_data_source.test.output}" + + required = "yep" + required_map = { + key = "value" + } +} + `), + Check: func(s *terraform.State) error { + count := 0 + for k, _ := range s.RootModule().Resources { + if strings.HasPrefix(k, "test_resource.foo.") { + count++ + } + } + + if count != 4 { + return fmt.Errorf("bad count: %d", count) + } + return nil + }, + }, + }, + }) +}