command: test that terraform meta information is passed through
This commit is contained in:
parent
9900bd752a
commit
d475fc29a8
|
@ -603,9 +603,7 @@ func TestApply_plan_backup(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state-out", statePath,
|
||||
args := []string{"-state-out", statePath,
|
||||
"-backup", backupPath,
|
||||
planPath,
|
||||
}
|
||||
|
@ -1531,6 +1529,91 @@ func TestApply_disableBackup(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Test that the Terraform env is passed through
|
||||
func TestApply_terraformEnv(t *testing.T) {
|
||||
statePath := testTempFile(t)
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
testFixturePath("apply-terraform-env"),
|
||||
}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
expected := strings.TrimSpace(`
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
output = default
|
||||
`)
|
||||
testStateOutput(t, statePath, expected)
|
||||
}
|
||||
|
||||
// Test that the Terraform env is passed through
|
||||
func TestApply_terraformEnvNonDefault(t *testing.T) {
|
||||
// Create a temporary working directory that is empty
|
||||
td := tempDir(t)
|
||||
os.MkdirAll(td, 0755)
|
||||
defer os.RemoveAll(td)
|
||||
defer testChdir(t, td)()
|
||||
|
||||
// Create new env
|
||||
{
|
||||
ui := new(cli.MockUi)
|
||||
newCmd := &EnvNewCommand{}
|
||||
newCmd.Meta = Meta{Ui: ui}
|
||||
if code := newCmd.Run([]string{"test"}); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
|
||||
}
|
||||
}
|
||||
|
||||
// Switch to it
|
||||
{
|
||||
args := []string{"test"}
|
||||
ui := new(cli.MockUi)
|
||||
selCmd := &EnvSelectCommand{}
|
||||
selCmd.Meta = Meta{Ui: ui}
|
||||
if code := selCmd.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter)
|
||||
}
|
||||
}
|
||||
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
c := &ApplyCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfig(p),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
args := []string{
|
||||
testFixturePath("apply-terraform-env"),
|
||||
}
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
statePath := filepath.Join("terraform.tfstate.d", "test", "terraform.tfstate")
|
||||
expected := strings.TrimSpace(`
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
output = test
|
||||
`)
|
||||
testStateOutput(t, statePath, expected)
|
||||
}
|
||||
|
||||
func testHttpServer(t *testing.T) net.Listener {
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
|
|
|
@ -208,11 +208,16 @@ func (m *Meta) contextOpts() *terraform.ContextOpts {
|
|||
vs[k] = v
|
||||
}
|
||||
opts.Variables = vs
|
||||
|
||||
opts.Targets = m.targets
|
||||
opts.UIInput = m.UIInput()
|
||||
opts.Parallelism = m.parallelism
|
||||
opts.Shadow = m.shadow
|
||||
|
||||
opts.Meta = &terraform.ContextMeta{
|
||||
Env: m.Env(),
|
||||
}
|
||||
|
||||
return &opts
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
output "output" { value = "${terraform.env}" }
|
Loading…
Reference in New Issue