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.
This commit is contained in:
Martin Atkins 2018-09-26 09:51:40 -07:00
parent 9179cdcbc6
commit 48dd8ddec5

View File

@ -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 {