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.
This commit is contained in:
Martin Atkins 2018-11-15 14:45:10 -08:00
parent b316e4ab56
commit be79bf0412
2 changed files with 11 additions and 1 deletions

View File

@ -462,6 +462,16 @@ func (m *Meta) backendFromConfig(opts *BackendOpts) (backend.Backend, tfdiags.Di
// Potentially changing a backend configuration // Potentially changing a backend configuration
case c != nil && !s.Backend.Empty(): 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 // If our configuration is the same, then we're just initializing
// a previously configured remote backend. // a previously configured remote backend.
if !m.backendConfigNeedsMigration(c, s.Backend) { if !m.backendConfigNeedsMigration(c, s.Backend) {

View File

@ -342,7 +342,7 @@ func TestPlan_outBackend(t *testing.T) {
} }
if code := c.Run(args); code != 0 { if code := c.Run(args); code != 0 {
t.Logf("stdout: %s", ui.OutputWriter.String()) 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) plan := testReadPlan(t, outPath)