From be79bf0412dce80dbcc391de8684e042fb9e8cec Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 15 Nov 2018 14:45:10 -0800 Subject: [PATCH] command: Fix TestPlan_outBackend In an earlier change we fixed the "backendFromConfig" codepath to be able to properly detect changes to the -backend-config arguments during "terraform init", but this detection is too strict for the normal case of running an operation in a previously-initialized directory. Before any of the recent changes, the logic here was to selectively update the hash to include -backend-config settings in the init case. Since that late hash recalculation was confusing, here we take the alternative path of using the hash only in the normal case and full value comparison in the init case. Treating both of these cases separately makes things marginally easier to follow here. --- command/meta_backend.go | 10 ++++++++++ command/plan_test.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/command/meta_backend.go b/command/meta_backend.go index f519ebcec2..a6a9da4c06 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -462,6 +462,16 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di // Potentially changing a backend configuration case c != nil && !s.Backend.Empty(): + // If we're not initializing, then it's sufficient for the configuration + // hashes to match, since that suggests that the static backend + // settings in the configuration files are unchanged. (The only + // record we have of CLI overrides is in the settings cache in this + // case, so we have no other source to compare with. + if !opts.Init && cHash == s.Backend.Hash { + log.Printf("[TRACE] Meta.Backend: using already-initialized, unchanged %q backend configuration", c.Type) + return m.backend_C_r_S_unchanged(c, cHash, sMgr) + } + // If our configuration is the same, then we're just initializing // a previously configured remote backend. if !m.backendConfigNeedsMigration(c, s.Backend) { diff --git a/command/plan_test.go b/command/plan_test.go index 1abd6c9f37..3220968f99 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -342,7 +342,7 @@ func TestPlan_outBackend(t *testing.T) { } if code := c.Run(args); code != 0 { t.Logf("stdout: %s", ui.OutputWriter.String()) - t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + t.Fatalf("plan command failed with exit code %d\n\n%s", code, ui.ErrorWriter.String()) } plan := testReadPlan(t, outPath)