From da46e16f4f82fa9f6e760f758d9ee4373245fa0e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 6 Mar 2015 15:14:41 -0800 Subject: [PATCH] command/push: can set the name on the CLI --- command/push.go | 22 +++++++++++++++------- command/push_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/command/push.go b/command/push.go index 75434a0d4d..bb5efc5b7f 100644 --- a/command/push.go +++ b/command/push.go @@ -22,11 +22,13 @@ type PushCommand struct { func (c *PushCommand) Run(args []string) int { var atlasToken string var moduleLock bool + var name string args = c.Meta.process(args, false) cmdFlags := c.Meta.flagSet("push") cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path") cmdFlags.StringVar(&atlasToken, "token", "", "") cmdFlags.BoolVar(&moduleLock, "module-lock", true, "") + cmdFlags.StringVar(&name, "name", "", "") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -86,14 +88,16 @@ func (c *PushCommand) Run(args []string) int { // Get the configuration config := ctx.Module().Config() - if config.Atlas == nil || config.Atlas.Name == "" { - c.Ui.Error( - "The name of this Terraform configuration in Atlas must be\n" + - "specified within your configuration or the command-line. To\n" + - "set it on the command-line, use the `-name` parameter.") - return 1 + if name == "" { + if config.Atlas == nil || config.Atlas.Name == "" { + c.Ui.Error( + "The name of this Terraform configuration in Atlas must be\n" + + "specified within your configuration or the command-line. To\n" + + "set it on the command-line, use the `-name` parameter.") + return 1 + } + name = config.Atlas.Name } - name := config.Atlas.Name // Get the variables we might already have vars, err := c.client.Get(name) @@ -164,6 +168,10 @@ Options: their current checkout and uploaded completely. This prevents Atlas from running "terraform get". + -name= Name of the configuration in Atlas. This can also + be set in the configuration itself. Format is + typically: "username/name". + -token= Access token to use to upload. If blank, the ATLAS_TOKEN environmental variable will be used. diff --git a/command/push_test.go b/command/push_test.go index de91a759f5..edd92897e6 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -176,6 +176,48 @@ func TestPush_inputPartial(t *testing.T) { } } +func TestPush_name(t *testing.T) { + 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, + } + + args := []string{ + "-name", "bar", + testFixturePath("push"), + } + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + if client.UpsertOptions.Name != "bar" { + t.Fatalf("bad: %#v", client.UpsertOptions) + } +} + func TestPush_noState(t *testing.T) { tmp, cwd := testCwd(t) defer testFixCwd(t, tmp, cwd)