terraform: tests for increasing count from 1 to > 1
This commit is contained in:
parent
c5a0b9cb40
commit
3b3c9e140a
|
@ -668,7 +668,7 @@ func TestContextPlan_count(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextPlan_countDecrease(t *testing.T) {
|
func TestContextPlan_countDecreaseToOne(t *testing.T) {
|
||||||
c := testConfig(t, "plan-count-dec")
|
c := testConfig(t, "plan-count-dec")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
|
@ -712,6 +712,42 @@ func TestContextPlan_countDecrease(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContextPlan_countIncreaseFromOne(t *testing.T) {
|
||||||
|
c := testConfig(t, "plan-count-inc")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
s := &State{
|
||||||
|
Resources: map[string]*ResourceState{
|
||||||
|
"aws_instance.foo": &ResourceState{
|
||||||
|
ID: "bar",
|
||||||
|
Type: "aws_instance",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"foo": "foo",
|
||||||
|
"type": "aws_instance",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctx := testContext(t, &ContextOpts{
|
||||||
|
Config: c,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
State: s,
|
||||||
|
})
|
||||||
|
|
||||||
|
plan, err := ctx.Plan(nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(plan.String())
|
||||||
|
expected := strings.TrimSpace(testTerraformPlanCountIncreaseStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad:\n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextPlan_destroy(t *testing.T) {
|
func TestContextPlan_destroy(t *testing.T) {
|
||||||
c := testConfig(t, "plan-destroy")
|
c := testConfig(t, "plan-destroy")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -172,10 +172,18 @@ func graphAddConfigResources(
|
||||||
if s != nil {
|
if s != nil {
|
||||||
state = s.Resources[name]
|
state = s.Resources[name]
|
||||||
|
|
||||||
// If the count is one, check the state for ".0" appended, which
|
if state == nil {
|
||||||
// might exist if we go from count > 1 to count == 1.
|
if r.Count == 1 {
|
||||||
if state == nil && r.Count == 1 {
|
// If the count is one, check the state for ".0"
|
||||||
state = s.Resources[r.Id()+".0"]
|
// appended, which might exist if we go from
|
||||||
|
// count > 1 to count == 1.
|
||||||
|
state = s.Resources[r.Id()+".0"]
|
||||||
|
} else if i == 0 {
|
||||||
|
// If count is greater than one, check for state
|
||||||
|
// with just the ID, which might exist if we go
|
||||||
|
// from count == 1 to count > 1
|
||||||
|
state = s.Resources[r.Id()]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if state == nil {
|
if state == nil {
|
||||||
|
|
|
@ -203,6 +203,27 @@ aws_instance.foo.2:
|
||||||
ID = bar
|
ID = bar
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testTerraformPlanCountIncreaseStr = `
|
||||||
|
DIFF:
|
||||||
|
|
||||||
|
UPDATE: aws_instance.bar
|
||||||
|
foo: "" => "bar"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
UPDATE: aws_instance.foo.1
|
||||||
|
foo: "" => "foo"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
UPDATE: aws_instance.foo.2
|
||||||
|
foo: "" => "foo"
|
||||||
|
type: "" => "aws_instance"
|
||||||
|
|
||||||
|
STATE:
|
||||||
|
|
||||||
|
aws_instance.foo:
|
||||||
|
ID = bar
|
||||||
|
foo = foo
|
||||||
|
type = aws_instance
|
||||||
|
`
|
||||||
|
|
||||||
const testTerraformPlanDestroyStr = `
|
const testTerraformPlanDestroyStr = `
|
||||||
DIFF:
|
DIFF:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
resource "aws_instance" "foo" {
|
||||||
|
foo = "foo"
|
||||||
|
count = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
foo = "bar"
|
||||||
|
}
|
Loading…
Reference in New Issue