terraform: test count == zero
This commit is contained in:
parent
e4ba737392
commit
221e40a3a9
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -477,6 +477,18 @@ STATE:
|
|||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanCountZeroStr = `
|
||||
DIFF:
|
||||
|
||||
CREATE: aws_instance.bar
|
||||
foo: "" => ""
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanCountVarStr = `
|
||||
DIFF:
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
resource "aws_instance" "foo" {
|
||||
count = 0
|
||||
foo = "foo"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.*.foo}"
|
||||
}
|
Loading…
Reference in New Issue