Skip to content

Commit dd8ee38

Browse files
committed
providers/test: additional testing via integration tests
1 parent b8c310c commit dd8ee38

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

builtin/providers/test/data_source_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"errors"
5+
"fmt"
56
"strings"
67
"testing"
78

@@ -55,3 +56,46 @@ resource "test_resource" "foo" {
5556
},
5657
})
5758
}
59+
60+
// Test that the output of a data source can be used as the value for
61+
// a "count" in a real resource. This would fail with "count cannot be computed"
62+
// at some point.
63+
func TestDataSource_valueAsResourceCount(t *testing.T) {
64+
resource.UnitTest(t, resource.TestCase{
65+
Providers: testAccProviders,
66+
CheckDestroy: func(s *terraform.State) error {
67+
return nil
68+
},
69+
Steps: []resource.TestStep{
70+
{
71+
Config: strings.TrimSpace(`
72+
data "test_data_source" "test" {
73+
input = "4"
74+
}
75+
76+
resource "test_resource" "foo" {
77+
count = "${data.test_data_source.test.output}"
78+
79+
required = "yep"
80+
required_map = {
81+
key = "value"
82+
}
83+
}
84+
`),
85+
Check: func(s *terraform.State) error {
86+
count := 0
87+
for k, _ := range s.RootModule().Resources {
88+
if strings.HasPrefix(k, "test_resource.foo.") {
89+
count++
90+
}
91+
}
92+
93+
if count != 4 {
94+
return fmt.Errorf("bad count: %d", count)
95+
}
96+
return nil
97+
},
98+
},
99+
},
100+
})
101+
}

0 commit comments

Comments
 (0)