|
|
|
|
@ -406,6 +406,108 @@ func TestInit_copyBackendDst(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInit_backendReinitWithExtra(t *testing.T) {
|
|
|
|
|
td := tempDir(t)
|
|
|
|
|
copy.CopyDir(testFixturePath("init-backend-empty"), td)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
|
|
m := testMetaBackend(t, nil)
|
|
|
|
|
opts := &BackendOpts{
|
|
|
|
|
ConfigExtra: map[string]interface{}{"path": "hello"},
|
|
|
|
|
Init: true,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err := m.backendConfig(opts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &InitCommand{
|
|
|
|
|
Meta: Meta{
|
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
|
Ui: ui,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := []string{"-backend-config", "path=hello"}
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read our saved backend config and verify we have our settings
|
|
|
|
|
state := testStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename))
|
|
|
|
|
if v := state.Backend.Config["path"]; v != "hello" {
|
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if state.Backend.Hash != b.Hash {
|
|
|
|
|
t.Fatal("mismatched state and config backend hashes")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if state.Backend.Rehash() != b.Rehash() {
|
|
|
|
|
t.Fatal("mismatched state and config re-hashes")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// init again and make sure nothing changes
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
state = testStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename))
|
|
|
|
|
if v := state.Backend.Config["path"]; v != "hello" {
|
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if state.Backend.Hash != b.Hash {
|
|
|
|
|
t.Fatal("mismatched state and config backend hashes")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// move option from config to -backend-config args
|
|
|
|
|
func TestInit_backendReinitConfigToExtra(t *testing.T) {
|
|
|
|
|
td := tempDir(t)
|
|
|
|
|
copy.CopyDir(testFixturePath("init-backend"), td)
|
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
defer testChdir(t, td)()
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &InitCommand{
|
|
|
|
|
Meta: Meta{
|
|
|
|
|
ContextOpts: testCtxConfig(testProvider()),
|
|
|
|
|
Ui: ui,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if code := c.Run([]string{"-input=false"}); code != 0 {
|
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read our saved backend config and verify we have our settings
|
|
|
|
|
state := testStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename))
|
|
|
|
|
if v := state.Backend.Config["path"]; v != "foo" {
|
|
|
|
|
t.Fatalf("bad: %#v", v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
backendHash := state.Backend.Hash
|
|
|
|
|
|
|
|
|
|
// init again but remove the path option from the config
|
|
|
|
|
cfg := "terraform {\n backend \"local\" {}\n}\n"
|
|
|
|
|
if err := ioutil.WriteFile("main.tf", []byte(cfg), 0644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := []string{"-input=false", "-backend-config=path=foo"}
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
state = testStateRead(t, filepath.Join(DefaultDataDir, DefaultStateFilename))
|
|
|
|
|
|
|
|
|
|
if state.Backend.Hash == backendHash {
|
|
|
|
|
t.Fatal("state.Backend.Hash was not updated")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
func TestInit_remoteState(t *testing.T) {
|
|
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
|
|