command/init: -backend-config
This commit is contained in:
parent
abb523cc78
commit
0299e60e83
|
@ -18,14 +18,12 @@ type InitCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *InitCommand) Run(args []string) int {
|
func (c *InitCommand) Run(args []string) int {
|
||||||
var remoteBackend, remoteAddress, remoteAccessToken, remoteName, remotePath string
|
var remoteBackend string
|
||||||
args = c.Meta.process(args, false)
|
args = c.Meta.process(args, false)
|
||||||
|
remoteConfig := make(map[string]string)
|
||||||
cmdFlags := flag.NewFlagSet("init", flag.ContinueOnError)
|
cmdFlags := flag.NewFlagSet("init", flag.ContinueOnError)
|
||||||
cmdFlags.StringVar(&remoteBackend, "backend", "atlas", "")
|
cmdFlags.StringVar(&remoteBackend, "backend", "", "")
|
||||||
cmdFlags.StringVar(&remoteAddress, "address", "", "")
|
cmdFlags.Var((*FlagKV)(&remoteConfig), "backend-config", "config")
|
||||||
cmdFlags.StringVar(&remoteAccessToken, "access-token", "", "")
|
|
||||||
cmdFlags.StringVar(&remoteName, "name", "", "")
|
|
||||||
cmdFlags.StringVar(&remotePath, "path", "", "")
|
|
||||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
|
@ -91,15 +89,10 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle remote state if configured
|
// Handle remote state if configured
|
||||||
if remoteAddress != "" || remoteAccessToken != "" || remoteName != "" || remotePath != "" {
|
if remoteBackend != "" {
|
||||||
var remoteConf terraform.RemoteState
|
var remoteConf terraform.RemoteState
|
||||||
remoteConf.Type = remoteBackend
|
remoteConf.Type = remoteBackend
|
||||||
remoteConf.Config = map[string]string{
|
remoteConf.Config = remoteConfig
|
||||||
"address": remoteAddress,
|
|
||||||
"access_token": remoteAccessToken,
|
|
||||||
"name": remoteName,
|
|
||||||
"path": remotePath,
|
|
||||||
}
|
|
||||||
|
|
||||||
state, err := c.State()
|
state, err := c.State()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -162,7 +162,7 @@ func TestInit_remoteState(t *testing.T) {
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-backend", "http",
|
"-backend", "http",
|
||||||
"-address", conf.Config["address"],
|
"-backend-config", "address=" + conf.Config["address"],
|
||||||
testFixturePath("init"),
|
testFixturePath("init"),
|
||||||
tmp,
|
tmp,
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ func TestInit_remoteStateWithLocal(t *testing.T) {
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-backend", "http",
|
"-backend", "http",
|
||||||
"-address", "http://google.com",
|
"-backend-config", "address=http://google.com",
|
||||||
testFixturePath("init"),
|
testFixturePath("init"),
|
||||||
}
|
}
|
||||||
if code := c.Run(args); code == 0 {
|
if code := c.Run(args); code == 0 {
|
||||||
|
@ -244,7 +244,7 @@ func TestInit_remoteStateWithRemote(t *testing.T) {
|
||||||
|
|
||||||
args := []string{
|
args := []string{
|
||||||
"-backend", "http",
|
"-backend", "http",
|
||||||
"-address", "http://google.com",
|
"-backend-config", "address=http://google.com",
|
||||||
testFixturePath("init"),
|
testFixturePath("init"),
|
||||||
}
|
}
|
||||||
if code := c.Run(args); code == 0 {
|
if code := c.Run(args); code == 0 {
|
||||||
|
|
Loading…
Reference in New Issue