Browse Source

Merge fe63d082cc into 08402ee4d0

pull/66/merge
SteveKMin 7 years ago
committed by GitHub
parent
commit
c1c08ed5bf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      DOCS.md
  2. 6
      main.go
  3. 22
      plugin.go

6
DOCS.md

@ -202,6 +202,9 @@ init_options.lock
init_options.lock-timeout
: Duration to wait for a state lock. Default `0s`.
init_options.plugin-path
: Local path to use terraform plugins from. Default is `""` which will pull from upstream Terraform.
vars
: a map of variables to pass to the Terraform `plan` and `apply` commands.
Each value is passed as a `-var <key>=<value>` option.
@ -216,6 +219,9 @@ ca_cert
sensitive
: (default: `false`) - Whether or not to suppress terraform commands to stdout.
plugin_dir
: (default: `false`) - Wheter or not to set custom plugin directory path.
role_arn_to_assume
: A role to assume before running the terraform commands.

6
main.go

@ -78,6 +78,11 @@ func main() {
Usage: "a map of secrets to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `<key>=<ENV>` option",
EnvVar: "PLUGIN_SECRETS",
},
cli.StringFlag{
Name: "plugin_dir",
Usage: "whether or not to set custom plugin directory path",
EnvVar: "PLUGIN_DIR",
},
cli.BoolFlag{
Name: "sensitive",
Usage: "whether or not to suppress terraform commands to stdout",
@ -148,6 +153,7 @@ func run(c *cli.Context) error {
Parallelism: c.Int("parallelism"),
Targets: c.StringSlice("targets"),
VarFiles: c.StringSlice("var_files"),
PluginDir: c.Bool("plugin_dir"),
},
Netrc: Netrc{
Login: c.String("netrc.username"),

22
plugin.go

@ -32,6 +32,7 @@ type (
Parallelism int
Targets []string
VarFiles []string
PluginDir bool
}
Netrc struct {
@ -45,6 +46,7 @@ type (
BackendConfig []string `json:"backend-config"`
Lock *bool `json:"lock"`
LockTimeout string `json:"lock-timeout"`
PluginPath string `json:"plugin-path`
}
// Plugin represents the plugin instance to be executed
@ -87,7 +89,7 @@ func (p Plugin) Exec() error {
}
commands = append(commands, deleteCache())
commands = append(commands, initCommand(p.Config.InitOptions))
commands = append(commands, initCommand(p.Config))
commands = append(commands, getModules())
// Add commands listed from Actions
@ -186,23 +188,29 @@ 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))
}
if config.PluginDir == true {
if config.InitOptions.PluginPath != "" {
args = append(args, fmt.Sprintf("-plugin-dir=%s", config.InitOptions.PluginPath))
}
}
// Fail Terraform execution on prompt

Loading…
Cancel
Save