terraform: further tests around count edge cases, fix 1 => N case

/cc @pearkes

GH-35
This commit is contained in:
Mitchell Hashimoto 2014-07-26 14:55:42 -07:00
parent f9f4e62411
commit a3639b6156
3 changed files with 61 additions and 5 deletions

View File

@ -1388,7 +1388,7 @@ func TestContextPlan_countDecreaseToOne(t *testing.T) {
}
}
func TestContextPlan_countIncreaseFromOne(t *testing.T) {
func TestContextPlan_countIncreaseFromNotSet(t *testing.T) {
c := testConfig(t, "plan-count-inc")
p := testProvider("aws")
p.DiffFn = testDiffFn
@ -1424,6 +1424,42 @@ func TestContextPlan_countIncreaseFromOne(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.0": &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(testTerraformPlanCountIncreaseFromOneStr)
if actual != expected {
t.Fatalf("bad:\n%s", actual)
}
}
func TestContextPlan_destroy(t *testing.T) {
c := testConfig(t, "plan-destroy")
p := testProvider("aws")

View File

@ -72,10 +72,9 @@ func (s *State) Orphans(c *config.Config) []string {
for _, r := range c.Resources {
delete(keys, r.Id())
// If there is only one of this instance, then we alias that
// to the ".0" version as well so that it can count
if r.Count == 1 {
delete(keys, r.Id()+".0")
// Mark all the counts as not orphans.
for i := 0; i < r.Count; i++ {
delete(keys, fmt.Sprintf("%s.%d", r.Id(), i))
}
}

View File

@ -364,6 +364,27 @@ aws_instance.foo:
type = aws_instance
`
const testTerraformPlanCountIncreaseFromOneStr = `
DIFF:
CREATE: aws_instance.bar
foo: "" => "bar"
type: "" => "aws_instance"
CREATE: aws_instance.foo.1
foo: "" => "foo"
type: "" => "aws_instance"
CREATE: aws_instance.foo.2
foo: "" => "foo"
type: "" => "aws_instance"
STATE:
aws_instance.foo.0:
ID = bar
foo = foo
type = aws_instance
`
const testTerraformPlanDestroyStr = `
DIFF: