core: Skip ignore_changes handling for create actions

It doesn't make sense to ignore_changes when the prior value is null,
since we have to create something before we can ignore changes to it.

This change is verified by TestContext2Apply_ignoreChangesWildcard.
This commit is contained in:
Martin Atkins 2018-09-25 17:59:36 -07:00
parent 5c4545dac2
commit 9e0f7c10d9
2 changed files with 9 additions and 4 deletions

View File

@ -9002,15 +9002,14 @@ func TestContext2Apply_ignoreChangesWildcard(t *testing.T) {
})
if p, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
logDiagnostics(t, diags)
t.Fatal("plan failed")
} else {
t.Logf(legacyDiffComparisonString(p.Changes))
}
state, diags := ctx.Apply()
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
assertNoErrors(t, diags)
mod := state.RootModule()
if len(mod.Resources) != 1 {

View File

@ -415,6 +415,12 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
}
func (n *EvalDiff) processIgnoreChanges(schema *configschema.Block, prior, proposed cty.Value) (cty.Value, tfdiags.Diagnostics) {
// ignore_changes only applies when an object already exists, since we
// can't ignore changes to a thing we've not created yet.
if prior.IsNull() {
return proposed, nil
}
ignoreChanges := n.Config.Managed.IgnoreChanges
ignoreAll := n.Config.Managed.IgnoreAllChanges