From 9e0f7c10d92d8138a189093dd634e2e17006e500 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 25 Sep 2018 17:59:36 -0700 Subject: [PATCH] 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. --- terraform/context_apply_test.go | 7 +++---- terraform/eval_diff.go | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 58c61a393..c74dddfcd 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -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 { diff --git a/terraform/eval_diff.go b/terraform/eval_diff.go index 6f0dccfb4..40f89e56a 100644 --- a/terraform/eval_diff.go +++ b/terraform/eval_diff.go @@ -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