mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #4753 from hashicorp/b-init-state-path
command/init: put remote state config at proper path [GH-2927]
This commit is contained in:
commit
6dd31986fd
@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-getter"
|
"github.com/hashicorp/go-getter"
|
||||||
@ -52,6 +53,11 @@ func (c *InitCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the state out path to be the path requested for the module
|
||||||
|
// to be copied. This ensures any remote states gets setup in the
|
||||||
|
// proper directory.
|
||||||
|
c.Meta.dataDir = filepath.Join(path, DefaultDataDirectory)
|
||||||
|
|
||||||
source := args[0]
|
source := args[0]
|
||||||
|
|
||||||
// Get our pwd since we need it
|
// Get our pwd since we need it
|
||||||
|
@ -179,6 +179,42 @@ func TestInit_remoteState(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInit_remoteStateSubdir(t *testing.T) {
|
||||||
|
tmp, cwd := testCwd(t)
|
||||||
|
defer testFixCwd(t, tmp, cwd)
|
||||||
|
subdir := filepath.Join(tmp, "subdir")
|
||||||
|
|
||||||
|
s := terraform.NewState()
|
||||||
|
conf, srv := testRemoteState(t, s, 200)
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
ui := new(cli.MockUi)
|
||||||
|
c := &InitCommand{
|
||||||
|
Meta: Meta{
|
||||||
|
ContextOpts: testCtxConfig(testProvider()),
|
||||||
|
Ui: ui,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"-backend", "http",
|
||||||
|
"-backend-config", "address=" + conf.Config["address"],
|
||||||
|
testFixturePath("init"),
|
||||||
|
subdir,
|
||||||
|
}
|
||||||
|
if code := c.Run(args); code != 0 {
|
||||||
|
t.Fatalf("bad: \n%s", ui.ErrorWriter.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(subdir, "hello.tf")); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(filepath.Join(subdir, DefaultDataDir, DefaultStateFilename)); err != nil {
|
||||||
|
t.Fatalf("missing state: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestInit_remoteStateWithLocal(t *testing.T) {
|
func TestInit_remoteStateWithLocal(t *testing.T) {
|
||||||
tmp, cwd := testCwd(t)
|
tmp, cwd := testCwd(t)
|
||||||
defer testFixCwd(t, tmp, cwd)
|
defer testFixCwd(t, tmp, cwd)
|
||||||
|
Loading…
Reference in New Issue
Block a user