Browse Source

Add tf_in_automation parameter

pull/65/head
Rob Wilson 7 years ago
parent
commit
ef7eb2d003
  1. 1
      main.go
  2. 57
      plugin.go

1
main.go

@ -143,6 +143,7 @@ func run(c *cli.Context) error {
InitOptions: initOptions,
Cacert: c.String("ca_cert"),
Sensitive: c.Bool("sensitive"),
TfInAutomation: c.Bool("tf_in_automation"),
RoleARN: c.String("role_arn_to_assume"),
RootDir: c.String("root_dir"),
Parallelism: c.Int("parallelism"),

57
plugin.go

@ -27,6 +27,7 @@ type (
InitOptions InitOptions
Cacert string
Sensitive bool
TfInAutomation bool
RoleARN string
RootDir string
Parallelism int
@ -87,7 +88,8 @@ func (p Plugin) Exec() error {
}
commands = append(commands, deleteCache())
commands = append(commands, initCommand(p.Config.InitOptions))
//commands = append(commands, initCommand(p.Config.InitOptions))
commands = append(commands, initCommand(p.Config))
commands = append(commands, getModules())
// Add commands listed from Actions
@ -186,30 +188,37 @@ func getModules() *exec.Cmd {
)
}
func initCommand(config InitOptions) *exec.Cmd {
func initCommand(config Config) *exec.Cmd {
args := []string{
"init",
}
for _, v := range config.BackendConfig {
for _, v := range config.InitOptions.BackendConfig {
args = append(args, fmt.Sprintf("-backend-config=%s", v))
}
// True is default in TF
if config.Lock != nil {
args = append(args, fmt.Sprintf("-lock=%t", *config.Lock))
if config.InitOptions.Lock != nil {
args = append(args, fmt.Sprintf("-lock=%t", *config.InitOptions.Lock))
}
// "0s" is default in TF
if config.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.LockTimeout))
if config.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
// Fail Terraform execution on prompt
args = append(args, "-input=false")
var command string
if config.TfInAutomation {
command = fmt.Sprintf("TF_IN_AUTOMATION=true terraform")
} else {
command = fmt.Sprintf("terraform")
}
return exec.Command(
"terraform",
command,
args...,
)
}
@ -242,8 +251,14 @@ func tfApply(config Config) *exec.Cmd {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
args = append(args, "plan.tfout")
var command string
if config.TfInAutomation {
command = fmt.Sprintf("TF_IN_AUTOMATION=true terraform")
} else {
command = fmt.Sprintf("terraform")
}
return exec.Command(
"terraform",
command,
args...,
)
}
@ -265,8 +280,14 @@ func tfDestroy(config Config) *exec.Cmd {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
args = append(args, "-force")
var command string
if config.TfInAutomation {
command = fmt.Sprintf("TF_IN_AUTOMATION=true terraform")
} else {
command = fmt.Sprintf("terraform")
}
return exec.Command(
"terraform",
command,
args...,
)
}
@ -301,8 +322,14 @@ func tfPlan(config Config, destroy bool) *exec.Cmd {
if config.InitOptions.LockTimeout != "" {
args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout))
}
var command string
if config.TfInAutomation {
command = fmt.Sprintf("TF_IN_AUTOMATION=true terraform")
} else {
command = fmt.Sprintf("terraform")
}
return exec.Command(
"terraform",
command,
args...,
)
}
@ -318,8 +345,14 @@ func tfValidate(config Config) *exec.Cmd {
args = append(args, "-var")
args = append(args, fmt.Sprintf("%s=%s", k, v))
}
var command string
if config.TfInAutomation {
command = fmt.Sprintf("TF_IN_AUTOMATION=true terraform")
} else {
command = fmt.Sprintf("terraform")
}
return exec.Command(
"terraform",
command,
args...,
)
}

Loading…
Cancel
Save