terraform: test count == zero

This commit is contained in:
Mitchell Hashimoto 2014-10-02 17:18:40 -07:00
parent e4ba737392
commit 221e40a3a9
4 changed files with 48 additions and 1 deletions

View File

@ -1559,7 +1559,6 @@ func (c *walkContext) computeResourceMultiVariable(
// TODO: Not use only root module
module := c.Context.state.RootModule()
// TODO: handle computed here
count, err := cr.Count()
if err != nil {
return "", fmt.Errorf(
@ -1568,6 +1567,11 @@ func (c *walkContext) computeResourceMultiVariable(
err)
}
// If we have no count, return empty
if count == 0 {
return "", nil
}
var values []string
for i := 0; i < count; i++ {
id := fmt.Sprintf("%s.%d", v.ResourceId(), i)

View File

@ -2490,6 +2490,29 @@ func TestContextPlan_countVar(t *testing.T) {
}
}
func TestContextPlan_countZero(t *testing.T) {
m := testModule(t, "plan-count-zero")
p := testProvider("aws")
p.DiffFn = testDiffFn
ctx := testContext(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
plan, err := ctx.Plan(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanCountZeroStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_countDecreaseToOne(t *testing.T) {
m := testModule(t, "plan-count-dec")
p := testProvider("aws")

View File

@ -477,6 +477,18 @@ STATE:
<no state>
`
const testTerraformPlanCountZeroStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => ""
type: "" => "aws_instance"
STATE:
<no state>
`
const testTerraformPlanCountVarStr = `
DIFF:

View File

@ -0,0 +1,8 @@
resource "aws_instance" "foo" {
count = 0
foo = "foo"
}
resource "aws_instance" "bar" {
foo = "${aws_instance.foo.*.foo}"
}