From 48dd8ddec5256b3d09b9fe36994b11f5c2043a0a Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 26 Sep 2018 09:51:40 -0700 Subject: [PATCH] core: test helper contextOptsForPlanViaFile to set default backend A plan file without a backend set is not valid, but at the level we're testing in this package we don't really care about backends so we'll just set a default one if the caller doesn't set something more specific, and then we'll just ignore it completely when reading back. --- terraform/context_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/terraform/context_test.go b/terraform/context_test.go index 7a5b78ecd..5349bff6e 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -718,6 +718,20 @@ func contextOptsForPlanViaFile(configSnap *configload.Snapshot, state *states.St State: state, } + // To make life a little easier for test authors, we'll populate a simple + // backend configuration if they didn't set one, since the backend is + // usually dealt with in a calling package and so tests in this package + // don't really care about it. + if plan.Backend.Config == nil { + cfg, err := plans.NewDynamicValue(cty.EmptyObjectVal, cty.EmptyObject) + if err != nil { + panic(fmt.Sprintf("NewDynamicValue failed: %s", err)) // shouldn't happen because we control the inputs + } + plan.Backend.Type = "local" + plan.Backend.Config = cfg + plan.Backend.Workspace = "default" + } + filename := filepath.Join(dir, "tfplan") err = planfile.Create(filename, configSnap, stateFile, plan) if err != nil {