Add a failing test for missing keys in diff

ignore_changes is causing changes in other flatmapped sets to be
filtered out incorrectly.

This required fixing the testDiffFn to create diffs which include the
old value, breaking one other test.
This commit is contained in:
James Bardin 2017-03-20 17:17:14 -04:00
parent 14e07b136e
commit 970e7c1923
4 changed files with 82 additions and 0 deletions

View File

@ -3095,3 +3095,53 @@ func TestContext2Plan_listOrder(t *testing.T) {
t.Fatal("aws_instance.a and aws_instance.b diffs should match:\n", plan)
}
}
// Make sure ignore-changes doesn't interfere with set/list/map diffs.
// If a resource was being replaced by a RequiresNew attribute that gets
// ignores, we need to filter out the diff properly.
func TestContext2Plan_ignoreChangesWithFlatmaps(t *testing.T) {
m := testModule(t, "plan-ignore-changes-with-flatmaps")
p := testProvider("aws")
p.DiffFn = testDiffFn
s := &State{
Modules: []*ModuleState{
&ModuleState{
Path: rootModulePath,
Resources: map[string]*ResourceState{
"aws_instance.foo": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
Attributes: map[string]string{
"user_data": "x",
"require_new": "",
"set.#": "1",
"set.0.a": "1",
"lst.#": "1",
"lst.0": "j",
},
},
},
},
},
},
}
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
State: s,
})
plan, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.Diff.String())
expected := strings.TrimSpace(testTFPlanDiffIgnoreChangesWithFlatmaps)
if actual != expected {
t.Fatalf("bad:\n%s\n\nexpected\n\n%s", actual, expected)
}
}

View File

@ -262,6 +262,11 @@ func testDiffFn(
if _, ok := c.Raw["__"+k+"_requires_new"]; ok {
attrDiff.RequiresNew = true
}
if attr, ok := s.Attributes[k]; ok {
attrDiff.Old = attr
}
diff.Attributes[k] = attrDiff
}
}

View File

@ -1570,6 +1570,17 @@ aws_instance.foo:
ami = ami-abcd1234
`
const testTFPlanDiffIgnoreChangesWithFlatmaps = `
UPDATE: aws_instance.foo
lst.#: "1" => "2"
lst.0: "j" => "j"
lst.1: "" => "k"
set.#: "1" => "1"
set.0.a: "1" => "1"
set.0.b: "" => "2"
type: "" => "aws_instance"
`
const testTerraformPlanIgnoreChangesWildcardStr = `
DIFF:

View File

@ -0,0 +1,16 @@
resource "aws_instance" "foo" {
id = "bar"
user_data = "x"
require_new = "yes"
set = {
a = "1"
b = "2"
}
lst = ["j", "k"]
lifecycle {
ignore_changes = ["require_new"]
}
}