From 0299e60e8319bf3add41c797b70960dec9bce11d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Feb 2015 10:56:27 -0800 Subject: [PATCH] command/init: -backend-config --- command/init.go | 19 ++++++------------- command/init_test.go | 6 +++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/command/init.go b/command/init.go index 3651284df..8cb92d216 100644 --- a/command/init.go +++ b/command/init.go @@ -18,14 +18,12 @@ type InitCommand struct { } func (c *InitCommand) Run(args []string) int { - var remoteBackend, remoteAddress, remoteAccessToken, remoteName, remotePath string + var remoteBackend string args = c.Meta.process(args, false) + remoteConfig := make(map[string]string) cmdFlags := flag.NewFlagSet("init", flag.ContinueOnError) - cmdFlags.StringVar(&remoteBackend, "backend", "atlas", "") - cmdFlags.StringVar(&remoteAddress, "address", "", "") - cmdFlags.StringVar(&remoteAccessToken, "access-token", "", "") - cmdFlags.StringVar(&remoteName, "name", "", "") - cmdFlags.StringVar(&remotePath, "path", "", "") + cmdFlags.StringVar(&remoteBackend, "backend", "", "") + cmdFlags.Var((*FlagKV)(&remoteConfig), "backend-config", "config") cmdFlags.Usage = func() { c.Ui.Error(c.Help()) } if err := cmdFlags.Parse(args); err != nil { return 1 @@ -91,15 +89,10 @@ func (c *InitCommand) Run(args []string) int { } // Handle remote state if configured - if remoteAddress != "" || remoteAccessToken != "" || remoteName != "" || remotePath != "" { + if remoteBackend != "" { var remoteConf terraform.RemoteState remoteConf.Type = remoteBackend - remoteConf.Config = map[string]string{ - "address": remoteAddress, - "access_token": remoteAccessToken, - "name": remoteName, - "path": remotePath, - } + remoteConf.Config = remoteConfig state, err := c.State() if err != nil { diff --git a/command/init_test.go b/command/init_test.go index 335f7df0e..304c04009 100644 --- a/command/init_test.go +++ b/command/init_test.go @@ -162,7 +162,7 @@ func TestInit_remoteState(t *testing.T) { args := []string{ "-backend", "http", - "-address", conf.Config["address"], + "-backend-config", "address=" + conf.Config["address"], testFixturePath("init"), tmp, } @@ -206,7 +206,7 @@ func TestInit_remoteStateWithLocal(t *testing.T) { args := []string{ "-backend", "http", - "-address", "http://google.com", + "-backend-config", "address=http://google.com", testFixturePath("init"), } if code := c.Run(args); code == 0 { @@ -244,7 +244,7 @@ func TestInit_remoteStateWithRemote(t *testing.T) { args := []string{ "-backend", "http", - "-address", "http://google.com", + "-backend-config", "address=http://google.com", testFixturePath("init"), } if code := c.Run(args); code == 0 {