From 000d28c489681b9ed578e3b2fd417abacc3ced39 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Apr 2015 15:34:06 -0700 Subject: [PATCH] command/push: read terraform.tfvars --- command/push.go | 2 +- command/push_test.go | 69 +++++++++++++++++++ command/test-fixtures/push-tfvars/main.tf | 8 +++ .../push-tfvars/terraform.tfvars | 2 + 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 command/test-fixtures/push-tfvars/main.tf create mode 100644 command/test-fixtures/push-tfvars/terraform.tfvars diff --git a/command/push.go b/command/push.go index 1a12a7559..5f9bde51d 100644 --- a/command/push.go +++ b/command/push.go @@ -24,7 +24,7 @@ func (c *PushCommand) Run(args []string) int { var atlasAddress, atlasToken string var archiveVCS, moduleUpload bool var name string - args = c.Meta.process(args, false) + args = c.Meta.process(args, true) cmdFlags := c.Meta.flagSet("push") cmdFlags.StringVar(&atlasAddress, "atlas-address", "", "") cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path") diff --git a/command/push_test.go b/command/push_test.go index edd92897e..d771cc3b7 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -176,6 +176,75 @@ func TestPush_inputPartial(t *testing.T) { } } +func TestPush_inputTfvars(t *testing.T) { + // Disable test mode so input would be asked and setup the + // input reader/writers. + test = false + defer func() { test = true }() + defaultInputReader = bytes.NewBufferString("nope\n") + defaultInputWriter = new(bytes.Buffer) + + tmp, cwd := testCwd(t) + defer testFixCwd(t, tmp, cwd) + + // Create remote state file, this should be pulled + conf, srv := testRemoteState(t, testState(), 200) + defer srv.Close() + + // Persist local remote state + s := terraform.NewState() + s.Serial = 5 + s.Remote = conf + testStateFileRemote(t, s) + + // Path where the archive will be "uploaded" to + archivePath := testTempFile(t) + defer os.Remove(archivePath) + + client := &mockPushClient{File: archivePath} + ui := new(cli.MockUi) + c := &PushCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(testProvider()), + Ui: ui, + }, + + client: client, + } + + path := testFixturePath("push-tfvars") + args := []string{ + "-var-file", path + "/terraform.tfvars", + path, + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + actual := testArchiveStr(t, archivePath) + expected := []string{ + ".terraform/", + ".terraform/terraform.tfstate", + "main.tf", + "terraform.tfvars", + } + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad: %#v", actual) + } + + if client.UpsertOptions.Name != "foo" { + t.Fatalf("bad: %#v", client.UpsertOptions) + } + + variables := map[string]string{ + "foo": "bar", + "bar": "foo", + } + if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) { + t.Fatalf("bad: %#v", client.UpsertOptions) + } +} + func TestPush_name(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd) diff --git a/command/test-fixtures/push-tfvars/main.tf b/command/test-fixtures/push-tfvars/main.tf new file mode 100644 index 000000000..8285c1ada --- /dev/null +++ b/command/test-fixtures/push-tfvars/main.tf @@ -0,0 +1,8 @@ +variable "foo" {} +variable "bar" {} + +resource "test_instance" "foo" {} + +atlas { + name = "foo" +} diff --git a/command/test-fixtures/push-tfvars/terraform.tfvars b/command/test-fixtures/push-tfvars/terraform.tfvars new file mode 100644 index 000000000..92292f024 --- /dev/null +++ b/command/test-fixtures/push-tfvars/terraform.tfvars @@ -0,0 +1,2 @@ +foo = "bar" +bar = "foo"