mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
terraform: further tests around count edge cases, fix 1 => N case
/cc @pearkes GH-35
This commit is contained in:
parent
f9f4e62411
commit
a3639b6156
@ -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")
|
c := testConfig(t, "plan-count-inc")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.DiffFn = testDiffFn
|
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) {
|
func TestContextPlan_destroy(t *testing.T) {
|
||||||
c := testConfig(t, "plan-destroy")
|
c := testConfig(t, "plan-destroy")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
@ -72,10 +72,9 @@ func (s *State) Orphans(c *config.Config) []string {
|
|||||||
for _, r := range c.Resources {
|
for _, r := range c.Resources {
|
||||||
delete(keys, r.Id())
|
delete(keys, r.Id())
|
||||||
|
|
||||||
// If there is only one of this instance, then we alias that
|
// Mark all the counts as not orphans.
|
||||||
// to the ".0" version as well so that it can count
|
for i := 0; i < r.Count; i++ {
|
||||||
if r.Count == 1 {
|
delete(keys, fmt.Sprintf("%s.%d", r.Id(), i))
|
||||||
delete(keys, r.Id()+".0")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,6 +364,27 @@ aws_instance.foo:
|
|||||||
type = aws_instance
|
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 = `
|
const testTerraformPlanDestroyStr = `
|
||||||
DIFF:
|
DIFF:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user