command: updating for pluggable backends
This commit is contained in:
parent
dbaf4d3f2a
commit
6a84be0686
|
@ -19,12 +19,14 @@ type InitCommand struct {
|
|||
}
|
||||
|
||||
func (c *InitCommand) Run(args []string) int {
|
||||
var remoteConf terraform.RemoteState
|
||||
var remoteBackend, remoteAddress, remoteAccessToken, remoteName, remotePath string
|
||||
args = c.Meta.process(args, false)
|
||||
cmdFlags := flag.NewFlagSet("init", flag.ContinueOnError)
|
||||
cmdFlags.StringVar(&remoteConf.Name, "remote", "", "")
|
||||
cmdFlags.StringVar(&remoteConf.Server, "remote-server", "", "")
|
||||
cmdFlags.StringVar(&remoteConf.AuthToken, "remote-auth", "", "")
|
||||
cmdFlags.StringVar(&remoteBackend, "backend", "atlas", "")
|
||||
cmdFlags.StringVar(&remoteAddress, "address", "", "")
|
||||
cmdFlags.StringVar(&remoteAccessToken, "access-token", "", "")
|
||||
cmdFlags.StringVar(&remoteName, "name", "", "")
|
||||
cmdFlags.StringVar(&remotePath, "path", "", "")
|
||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||
if err := cmdFlags.Parse(args); err != nil {
|
||||
return 1
|
||||
|
@ -90,7 +92,16 @@ func (c *InitCommand) Run(args []string) int {
|
|||
}
|
||||
|
||||
// Handle remote state if configured
|
||||
if !remoteConf.Empty() {
|
||||
if remoteAddress != "" || remoteAccessToken != "" || remoteName != "" || remotePath != "" {
|
||||
var remoteConf terraform.RemoteState
|
||||
remoteConf.Type = remoteBackend
|
||||
remoteConf.Config = map[string]string{
|
||||
"address": remoteAddress,
|
||||
"access_token": remoteAccessToken,
|
||||
"name": remoteName,
|
||||
"path": remotePath,
|
||||
}
|
||||
|
||||
// Ensure remote state is not already enabled
|
||||
haveLocal, err := remote.HaveLocalState()
|
||||
if err != nil {
|
||||
|
@ -138,13 +149,20 @@ Usage: terraform init [options] SOURCE [PATH]
|
|||
|
||||
Options:
|
||||
|
||||
-remote=name Name of the state file in the state storage server.
|
||||
Optional, default does not use remote storage.
|
||||
-address=url URL of the remote storage server.
|
||||
Required for HTTP backend, optional for Atlas and Consul.
|
||||
|
||||
-remote-auth=token Authentication token for state storage server.
|
||||
Optional, defaults to blank.
|
||||
-access-token=token Authentication token for state storage server.
|
||||
Required for Atlas backend, optional for Consul.
|
||||
|
||||
-remote-server=url URL of the remote storage server.
|
||||
-backend=atlas Specifies the type of remote backend. Must be one
|
||||
of Atlas, Consul, or HTTP. Defaults to atlas.
|
||||
|
||||
-name=name Name of the state file in the state storage server.
|
||||
Required for Atlas backend.
|
||||
|
||||
-path=path Path of the remote state in Consul. Required for the
|
||||
Consul backend.
|
||||
|
||||
`
|
||||
return strings.TrimSpace(helpText)
|
||||
|
|
|
@ -162,8 +162,8 @@ func TestInit_remoteState(t *testing.T) {
|
|||
}
|
||||
|
||||
args := []string{
|
||||
"-remote", conf.Name,
|
||||
"-remote-server", conf.Server,
|
||||
"-backend", "http",
|
||||
"-address", conf.Config["address"],
|
||||
testFixturePath("init"),
|
||||
tmp,
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ func testRemoteState(t *testing.T, s *terraform.State, c int) (*terraform.Remote
|
|||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(cb))
|
||||
remote := &terraform.RemoteState{
|
||||
Name: "foo",
|
||||
Server: srv.URL,
|
||||
Type: "http",
|
||||
Config: map[string]string{"address": srv.URL},
|
||||
}
|
||||
return remote, srv
|
||||
}
|
||||
|
|
|
@ -32,19 +32,30 @@ type RemoteCommand struct {
|
|||
|
||||
func (c *RemoteCommand) Run(args []string) int {
|
||||
args = c.Meta.process(args, false)
|
||||
var address, accessToken, name, path string
|
||||
cmdFlags := flag.NewFlagSet("remote", flag.ContinueOnError)
|
||||
cmdFlags.BoolVar(&c.conf.disableRemote, "disable", false, "")
|
||||
cmdFlags.BoolVar(&c.conf.pullOnDisable, "pull", true, "")
|
||||
cmdFlags.StringVar(&c.conf.statePath, "state", DefaultStateFilename, "path")
|
||||
cmdFlags.StringVar(&c.conf.backupPath, "backup", "", "path")
|
||||
cmdFlags.StringVar(&c.remoteConf.AuthToken, "auth", "", "")
|
||||
cmdFlags.StringVar(&c.remoteConf.Name, "name", "", "")
|
||||
cmdFlags.StringVar(&c.remoteConf.Server, "server", "", "")
|
||||
cmdFlags.StringVar(&c.remoteConf.Type, "backend", "atlas", "")
|
||||
cmdFlags.StringVar(&address, "address", "", "")
|
||||
cmdFlags.StringVar(&accessToken, "access-token", "", "")
|
||||
cmdFlags.StringVar(&name, "name", "", "")
|
||||
cmdFlags.StringVar(&path, "path", "", "")
|
||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||
if err := cmdFlags.Parse(args); err != nil {
|
||||
return 1
|
||||
}
|
||||
|
||||
// Populate the various configurations
|
||||
c.remoteConf.Config = map[string]string{
|
||||
"address": address,
|
||||
"access_token": accessToken,
|
||||
"name": name,
|
||||
"path": path,
|
||||
}
|
||||
|
||||
// Check if have an existing local state file
|
||||
haveLocal, err := remote.HaveLocalState()
|
||||
if err != nil {
|
||||
|
@ -305,8 +316,14 @@ Usage: terraform remote [options]
|
|||
|
||||
Options:
|
||||
|
||||
-auth=token Authentication token for state storage server.
|
||||
Optional, defaults to blank.
|
||||
-address=url URL of the remote storage server.
|
||||
Required for HTTP backend, optional for Atlas and Consul.
|
||||
|
||||
-access-token=token Authentication token for state storage server.
|
||||
Required for Atlas backend, optional for Consul.
|
||||
|
||||
-backend=Atlas Specifies the type of remote backend. Must be one
|
||||
of Atlas, Consul, or HTTP. Defaults to Atlas.
|
||||
|
||||
-backup=path Path to backup the existing state file before
|
||||
modifying. Defaults to the "-state" path with
|
||||
|
@ -315,15 +332,16 @@ Options:
|
|||
-disable Disables remote state management and migrates the state
|
||||
to the -state path.
|
||||
|
||||
-name=name Name of the state file in the state storage server.
|
||||
Required for Atlas backend.
|
||||
|
||||
-path=path Path of the remote state in Consul. Required for the
|
||||
Consul backend.
|
||||
|
||||
-pull=true Controls if the remote state is pulled before disabling.
|
||||
This defaults to true to ensure the latest state is cached
|
||||
before disabling.
|
||||
|
||||
-name=name Name of the state file in the state storage server.
|
||||
Optional, default does not use remote storage.
|
||||
|
||||
-server=url URL of the remote storage server.
|
||||
|
||||
-state=path Path to read state. Defaults to "terraform.tfstate"
|
||||
unless remote state is enabled.
|
||||
|
||||
|
|
Loading…
Reference in New Issue