teraform: test that count can be a variable
This commit is contained in:
parent
039531e9ca
commit
ced4125037
|
@ -2428,6 +2428,32 @@ func TestContextPlan_count(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContextPlan_countVar(t *testing.T) {
|
||||
m := testModule(t, "plan-count-var")
|
||||
p := testProvider("aws")
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: map[string]string{
|
||||
"count": "3",
|
||||
},
|
||||
})
|
||||
|
||||
plan, err := ctx.Plan(nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanCountVarStr)
|
||||
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,27 @@ STATE:
|
|||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanCountVarStr = `
|
||||
DIFF:
|
||||
|
||||
CREATE: aws_instance.bar
|
||||
foo: "" => "foo,foo,foo"
|
||||
type: "" => "aws_instance"
|
||||
CREATE: aws_instance.foo.0
|
||||
foo: "" => "foo"
|
||||
type: "" => "aws_instance"
|
||||
CREATE: aws_instance.foo.1
|
||||
foo: "" => "foo"
|
||||
type: "" => "aws_instance"
|
||||
CREATE: aws_instance.foo.2
|
||||
foo: "" => "foo"
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformPlanCountDecreaseStr = `
|
||||
DIFF:
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
variable "count" {}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
count = "${var.count}"
|
||||
foo = "foo"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${aws_instance.foo.*.foo}"
|
||||
}
|
Loading…
Reference in New Issue