From a3571a2b101ce45f6430961924981e9468328879 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:35:07 -0600 Subject: [PATCH 01/10] Provide actions to run --- main.go | 19 +++++++------------ plugin.go | 48 +++++++++++++++++++++++++++--------------------- plugin_test.go | 40 +++++++--------------------------------- 3 files changed, 41 insertions(+), 66 deletions(-) diff --git a/main.go b/main.go index 65bc527..c1b97e9 100644 --- a/main.go +++ b/main.go @@ -23,11 +23,6 @@ func main() { // plugin args // - cli.BoolFlag{ - Name: "plan", - Usage: "calculates a plan but does NOT apply it", - EnvVar: "PLUGIN_PLAN", - }, cli.StringFlag{ Name: "init_options", Usage: "options for the init command. See https://www.terraform.io/docs/commands/init.html", @@ -85,16 +80,17 @@ func main() { Usage: "a list of var files to use. Each value is passed as -var-file=", EnvVar: "PLUGIN_VAR_FILES", }, - cli.BoolFlag{ - Name: "destroy", - Usage: "destory all resurces", - EnvVar: "PLUGIN_DESTROY", - }, cli.StringFlag{ Name: "tf.version", Usage: "terraform version to use", EnvVar: "PLUGIN_TF_VERSION", }, + cli.StringSliceFlag{ + Name: "actions", + Usage: "a list of actions to have terraform perform", + EnvVar: "PLUGIN_ACTIONS", + Value: &cli.StringSlice{"validate", "apply"}, + }, } if err := app.Run(os.Args); err != nil { @@ -129,7 +125,7 @@ func run(c *cli.Context) error { plugin := Plugin{ Config: Config{ - Plan: c.Bool("plan"), + Actions: c.StringSlice("actions"), Vars: vars, Secrets: secrets, InitOptions: initOptions, @@ -140,7 +136,6 @@ func run(c *cli.Context) error { Parallelism: c.Int("parallelism"), Targets: c.StringSlice("targets"), VarFiles: c.StringSlice("var_files"), - Destroy: c.Bool("destroy"), }, Terraform: Terraform{ Version: c.String("tf.version"), diff --git a/plugin.go b/plugin.go index 81c4d08..3be899b 100644 --- a/plugin.go +++ b/plugin.go @@ -19,7 +19,7 @@ import ( type ( // Config holds input parameters for the plugin Config struct { - Plan bool + Actions []string Vars map[string]string Secrets map[string]string InitOptions InitOptions @@ -30,7 +30,6 @@ type ( Parallelism int Targets []string VarFiles []string - Destroy bool } // InitOptions include options for the Terraform's init command @@ -73,15 +72,29 @@ func (p Plugin) Exec() error { } commands = append(commands, deleteCache()) - commands = append(commands, initCommand(p.Config.InitOptions)) - commands = append(commands, getModules()) - commands = append(commands, validateCommand(p.Config)) - commands = append(commands, planCommand(p.Config)) - if !p.Config.Plan { - commands = append(commands, terraformCommand(p.Config)) + + // Add commands listed from Actions + for _, action := range p.Config.Actions { + switch action { + case "validate": + commands = append(commands, tfValidate(p.Config)) + case "plan": + commands = append(commands, tfPlan(p.Config, false)) + case "plan-destroy": + commands = append(commands, tfPlan(p.Config, true)) + case "apply": + commands = append(commands, tfPlan(p.Config, false)) + commands = append(commands, tfApply(p.Config)) + case "destroy": + commands = append(commands, tfPlan(p.Config, true)) + commands = append(commands, tfDestroy(p.Config)) + default: + return fmt.Errorf("valid actions are: validate, plan, apply, destroy. You provided %s", action) + } } + commands = append(commands, deleteCache()) for _, c := range commands { @@ -173,7 +186,7 @@ func getModules() *exec.Cmd { ) } -func validateCommand(config Config) *exec.Cmd { +func tfValidate(config Config) *exec.Cmd { args := []string{ "validate", } @@ -190,11 +203,12 @@ func validateCommand(config Config) *exec.Cmd { ) } -func planCommand(config Config) *exec.Cmd { +func tfPlan(config Config, destroy bool) *exec.Cmd { args := []string{ "plan", } - if config.Destroy { + + if destroy { args = append(args, "-destroy") } else { args = append(args, "-out=plan.tfout") @@ -225,15 +239,7 @@ func planCommand(config Config) *exec.Cmd { ) } -func terraformCommand(config Config) *exec.Cmd { - if config.Destroy { - return destroyCommand(config) - } - - return applyCommand(config) -} - -func applyCommand(config Config) *exec.Cmd { +func tfApply(config Config) *exec.Cmd { args := []string{ "apply", } @@ -256,7 +262,7 @@ func applyCommand(config Config) *exec.Cmd { ) } -func destroyCommand(config Config) *exec.Cmd { +func tfDestroy(config Config) *exec.Cmd { args := []string{ "destroy", } diff --git a/plugin_test.go b/plugin_test.go index 6073d9c..4c6a48f 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -36,7 +36,7 @@ func Test_destroyCommand(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := destroyCommand(tt.args.config); !reflect.DeepEqual(got, tt.want) { + if got := tfDestroy(tt.args.config); !reflect.DeepEqual(got, tt.want) { t.Errorf("destroyCommand() = %v, want %v", got, tt.want) } }) @@ -70,42 +70,13 @@ func Test_applyCommand(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := applyCommand(tt.args.config); !reflect.DeepEqual(got, tt.want) { + if got := tfApply(tt.args.config); !reflect.DeepEqual(got, tt.want) { t.Errorf("applyCommand() = %v, want %v", got, tt.want) } }) } } -func Test_terraformCommand(t *testing.T) { - type args struct { - config Config - } - tests := []struct { - name string - args args - want *exec.Cmd - }{ - { - "default", - args{config: Config{}}, - exec.Command("terraform", "apply", "plan.tfout"), - }, - { - "destroy", - args{config: Config{Destroy: true}}, - exec.Command("terraform", "destroy", "-force"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := terraformCommand(tt.args.config); !reflect.DeepEqual(got, tt.want) { - t.Errorf("terraformCommand() = %v, want %v", got, tt.want) - } - }) - } -} - func Test_planCommand(t *testing.T) { type args struct { config Config @@ -113,22 +84,25 @@ func Test_planCommand(t *testing.T) { tests := []struct { name string args args + destroy bool want *exec.Cmd }{ { "default", args{config: Config{}}, + false, exec.Command("terraform", "plan", "-out=plan.tfout"), }, { "destroy", - args{config: Config{Destroy: true}}, + args{config: Config{}}, + true, exec.Command("terraform", "plan", "-destroy"), }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := planCommand(tt.args.config); !reflect.DeepEqual(got, tt.want) { + if got := tfPlan(tt.args.config, tt.destroy); !reflect.DeepEqual(got, tt.want) { t.Errorf("planCommand() = %v, want %v", got, tt.want) } }) From f308949c4a8250da62dad92163f9a1dfec575a18 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:36:56 -0600 Subject: [PATCH 02/10] Add comment to CopyTfEnv --- plugin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.go b/plugin.go index 3be899b..4384c17 100644 --- a/plugin.go +++ b/plugin.go @@ -132,6 +132,7 @@ func installCaCert(cacert string) *exec.Cmd { ) } +// CopyTfEnv creates copies of TF_VAR_ to lowercase func CopyTfEnv() { tfVar := regexp.MustCompile(`^TF_VAR_.*$`) for _, e := range os.Environ() { From 0faae5eb94364d16f7c51e3b09c9ae4f5d1352f6 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:39:20 -0600 Subject: [PATCH 03/10] Alphabetize flags --- main.go | 69 +++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/main.go b/main.go index c1b97e9..7c376e0 100644 --- a/main.go +++ b/main.go @@ -23,30 +23,30 @@ func main() { // plugin args // - cli.StringFlag{ - Name: "init_options", - Usage: "options for the init command. See https://www.terraform.io/docs/commands/init.html", - EnvVar: "PLUGIN_INIT_OPTIONS", + cli.StringSliceFlag{ + Name: "actions", + Usage: "a list of actions to have terraform perform", + EnvVar: "PLUGIN_ACTIONS", + Value: &cli.StringSlice{"validate", "apply"}, }, cli.StringFlag{ - Name: "vars", - Usage: "a map of variables to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `=` option", - EnvVar: "PLUGIN_VARS", + Name: "ca_cert", + Usage: "ca cert to add to your environment to allow terraform to use internal/private resources", + EnvVar: "PLUGIN_CA_CERT", }, cli.StringFlag{ - Name: "secrets", - Usage: "a map of secrets to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `=` option", - EnvVar: "PLUGIN_SECRETS", + Name: "env-file", + Usage: "source env file", }, cli.StringFlag{ - Name: "ca_cert", - Usage: "ca cert to add to your environment to allow terraform to use internal/private resources", - EnvVar: "PLUGIN_CA_CERT", + Name: "init_options", + Usage: "options for the init command. See https://www.terraform.io/docs/commands/init.html", + EnvVar: "PLUGIN_INIT_OPTIONS", }, - cli.BoolFlag{ - Name: "sensitive", - Usage: "whether or not to suppress terraform commands to stdout", - EnvVar: "PLUGIN_SENSITIVE", + cli.IntFlag{ + Name: "parallelism", + Usage: "The number of concurrent operations as Terraform walks its graph", + EnvVar: "PLUGIN_PARALLELISM", }, cli.StringFlag{ Name: "role_arn_to_assume", @@ -58,38 +58,35 @@ func main() { Usage: "The root directory where the terraform files live. When unset, the top level directory will be assumed", EnvVar: "PLUGIN_ROOT_DIR", }, - cli.IntFlag{ - Name: "parallelism", - Usage: "The number of concurrent operations as Terraform walks its graph", - EnvVar: "PLUGIN_PARALLELISM", - }, - cli.StringFlag{ - Name: "env-file", - Usage: "source env file", + Name: "secrets", + Usage: "a map of secrets to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `=` option", + EnvVar: "PLUGIN_SECRETS", + }, + cli.BoolFlag{ + Name: "sensitive", + Usage: "whether or not to suppress terraform commands to stdout", + EnvVar: "PLUGIN_SENSITIVE", }, - cli.StringSliceFlag{ Name: "targets", Usage: "targets to run apply or plan on", EnvVar: "PLUGIN_TARGETS", }, - - cli.StringSliceFlag{ - Name: "var_files", - Usage: "a list of var files to use. Each value is passed as -var-file=", - EnvVar: "PLUGIN_VAR_FILES", - }, cli.StringFlag{ Name: "tf.version", Usage: "terraform version to use", EnvVar: "PLUGIN_TF_VERSION", }, + cli.StringFlag{ + Name: "vars", + Usage: "a map of variables to pass to the Terraform `plan` and `apply` commands. Each value is passed as a `=` option", + EnvVar: "PLUGIN_VARS", + }, cli.StringSliceFlag{ - Name: "actions", - Usage: "a list of actions to have terraform perform", - EnvVar: "PLUGIN_ACTIONS", - Value: &cli.StringSlice{"validate", "apply"}, + Name: "var_files", + Usage: "a list of var files to use. Each value is passed as -var-file=", + EnvVar: "PLUGIN_VAR_FILES", }, } From 5401f4f43f3f0f3407b9d4f1384ee24d7a33bc80 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:47:07 -0600 Subject: [PATCH 04/10] (Mostly) alphabetize functions --- plugin.go | 140 +++++++++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/plugin.go b/plugin.go index 4384c17..5699203 100644 --- a/plugin.go +++ b/plugin.go @@ -125,13 +125,6 @@ func (p Plugin) Exec() error { return nil } -func installCaCert(cacert string) *exec.Cmd { - ioutil.WriteFile("/usr/local/share/ca-certificates/ca_cert.crt", []byte(cacert), 0644) - return exec.Command( - "update-ca-certificates", - ) -} - // CopyTfEnv creates copies of TF_VAR_ to lowercase func CopyTfEnv() { tfVar := regexp.MustCompile(`^TF_VAR_.*$`) @@ -144,6 +137,27 @@ func CopyTfEnv() { } } +func assumeRole(roleArn string) { + client := sts.New(session.New()) + duration := time.Hour * 1 + stsProvider := &stscreds.AssumeRoleProvider{ + Client: client, + Duration: duration, + RoleARN: roleArn, + RoleSessionName: "drone", + } + + value, err := credentials.NewCredentials(stsProvider).Get() + if err != nil { + logrus.WithFields(logrus.Fields{ + "error": err, + }).Fatal("Error assuming role!") + } + os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID) + os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey) + os.Setenv("AWS_SESSION_TOKEN", value.SessionToken) +} + func deleteCache() *exec.Cmd { return exec.Command( "rm", @@ -152,6 +166,13 @@ func deleteCache() *exec.Cmd { ) } +func getModules() *exec.Cmd { + return exec.Command( + "terraform", + "get", + ) +} + func initCommand(config InitOptions) *exec.Cmd { args := []string{ "init", @@ -180,51 +201,24 @@ func initCommand(config InitOptions) *exec.Cmd { ) } -func getModules() *exec.Cmd { +func installCaCert(cacert string) *exec.Cmd { + ioutil.WriteFile("/usr/local/share/ca-certificates/ca_cert.crt", []byte(cacert), 0644) return exec.Command( - "terraform", - "get", + "update-ca-certificates", ) } -func tfValidate(config Config) *exec.Cmd { - args := []string{ - "validate", - } - for _, v := range config.VarFiles { - args = append(args, "-var-file", fmt.Sprintf("%s", v)) - } - for k, v := range config.Vars { - args = append(args, "-var") - args = append(args, fmt.Sprintf("%s=%s", k, v)) - } - return exec.Command( - "terraform", - args..., - ) +func trace(cmd *exec.Cmd) { + fmt.Println("$", strings.Join(cmd.Args, " ")) } -func tfPlan(config Config, destroy bool) *exec.Cmd { +func tfApply(config Config) *exec.Cmd { args := []string{ - "plan", - } - - if destroy { - args = append(args, "-destroy") - } else { - args = append(args, "-out=plan.tfout") + "apply", } - for _, v := range config.Targets { args = append(args, "--target", fmt.Sprintf("%s", v)) } - for _, v := range config.VarFiles { - args = append(args, "-var-file", fmt.Sprintf("%s", v)) - } - for k, v := range config.Vars { - args = append(args, "-var") - args = append(args, fmt.Sprintf("%s=%s", k, v)) - } if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) } @@ -234,18 +228,19 @@ func tfPlan(config Config, destroy bool) *exec.Cmd { if config.InitOptions.LockTimeout != "" { args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) } + args = append(args, "plan.tfout") return exec.Command( "terraform", args..., ) } -func tfApply(config Config) *exec.Cmd { +func tfDestroy(config Config) *exec.Cmd { args := []string{ - "apply", + "destroy", } for _, v := range config.Targets { - args = append(args, "--target", fmt.Sprintf("%s", v)) + args = append(args, fmt.Sprintf("-target=%s", v)) } if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) @@ -256,19 +251,33 @@ func tfApply(config Config) *exec.Cmd { if config.InitOptions.LockTimeout != "" { args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) } - args = append(args, "plan.tfout") + args = append(args, "-force") return exec.Command( "terraform", args..., ) } -func tfDestroy(config Config) *exec.Cmd { +func tfPlan(config Config, destroy bool) *exec.Cmd { args := []string{ - "destroy", + "plan", } + + if destroy { + args = append(args, "-destroy") + } else { + args = append(args, "-out=plan.tfout") + } + for _, v := range config.Targets { - args = append(args, fmt.Sprintf("-target=%s", v)) + args = append(args, "--target", fmt.Sprintf("%s", v)) + } + for _, v := range config.VarFiles { + args = append(args, "-var-file", fmt.Sprintf("%s", v)) + } + for k, v := range config.Vars { + args = append(args, "-var") + args = append(args, fmt.Sprintf("%s=%s", k, v)) } if config.Parallelism > 0 { args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) @@ -279,34 +288,25 @@ func tfDestroy(config Config) *exec.Cmd { if config.InitOptions.LockTimeout != "" { args = append(args, fmt.Sprintf("-lock-timeout=%s", config.InitOptions.LockTimeout)) } - args = append(args, "-force") return exec.Command( "terraform", args..., ) } -func assumeRole(roleArn string) { - client := sts.New(session.New()) - duration := time.Hour * 1 - stsProvider := &stscreds.AssumeRoleProvider{ - Client: client, - Duration: duration, - RoleARN: roleArn, - RoleSessionName: "drone", +func tfValidate(config Config) *exec.Cmd { + args := []string{ + "validate", } - - value, err := credentials.NewCredentials(stsProvider).Get() - if err != nil { - logrus.WithFields(logrus.Fields{ - "error": err, - }).Fatal("Error assuming role!") + for _, v := range config.VarFiles { + args = append(args, "-var-file", fmt.Sprintf("%s", v)) } - os.Setenv("AWS_ACCESS_KEY_ID", value.AccessKeyID) - os.Setenv("AWS_SECRET_ACCESS_KEY", value.SecretAccessKey) - os.Setenv("AWS_SESSION_TOKEN", value.SessionToken) -} - -func trace(cmd *exec.Cmd) { - fmt.Println("$", strings.Join(cmd.Args, " ")) + for k, v := range config.Vars { + args = append(args, "-var") + args = append(args, fmt.Sprintf("%s=%s", k, v)) + } + return exec.Command( + "terraform", + args..., + ) } From 3e6f75540f6f4a728b9bdd90b04ee40d93aedcf0 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:57:57 -0600 Subject: [PATCH 05/10] Refactor all tests to utilize goblin --- plugin_test.go | 201 ++++++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 101 deletions(-) diff --git a/plugin_test.go b/plugin_test.go index 4c6a48f..baf59c0 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -3,112 +3,11 @@ package main import ( "os" "os/exec" - "reflect" "testing" . "github.com/franela/goblin" ) -func Test_destroyCommand(t *testing.T) { - type args struct { - config Config - } - tests := []struct { - name string - args args - want *exec.Cmd - }{ - { - "default", - args{config: Config{}}, - exec.Command("terraform", "destroy", "-force"), - }, - { - "with targets", - args{config: Config{Targets: []string{"target1", "target2"}}}, - exec.Command("terraform", "destroy", "-target=target1", "-target=target2", "-force"), - }, - { - "with parallelism", - args{config: Config{Parallelism: 5}}, - exec.Command("terraform", "destroy", "-parallelism=5", "-force"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tfDestroy(tt.args.config); !reflect.DeepEqual(got, tt.want) { - t.Errorf("destroyCommand() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_applyCommand(t *testing.T) { - type args struct { - config Config - } - tests := []struct { - name string - args args - want *exec.Cmd - }{ - { - "default", - args{config: Config{}}, - exec.Command("terraform", "apply", "plan.tfout"), - }, - { - "with targets", - args{config: Config{Targets: []string{"target1", "target2"}}}, - exec.Command("terraform", "apply", "--target", "target1", "--target", "target2", "plan.tfout"), - }, - { - "with parallelism", - args{config: Config{Parallelism: 5}}, - exec.Command("terraform", "apply", "-parallelism=5", "plan.tfout"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tfApply(tt.args.config); !reflect.DeepEqual(got, tt.want) { - t.Errorf("applyCommand() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_planCommand(t *testing.T) { - type args struct { - config Config - } - tests := []struct { - name string - args args - destroy bool - want *exec.Cmd - }{ - { - "default", - args{config: Config{}}, - false, - exec.Command("terraform", "plan", "-out=plan.tfout"), - }, - { - "destroy", - args{config: Config{}}, - true, - exec.Command("terraform", "plan", "-destroy"), - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := tfPlan(tt.args.config, tt.destroy); !reflect.DeepEqual(got, tt.want) { - t.Errorf("planCommand() = %v, want %v", got, tt.want) - } - }) - } -} - func TestPlugin(t *testing.T) { g := Goblin(t) @@ -127,4 +26,104 @@ func TestPlugin(t *testing.T) { g.Assert(os.Getenv("TF_VAR_base64")).Equal("dGVzdA==") }) }) + + g.Describe("tfApply", func() { + g.It("Should return correct apply commands given the arguments", func() { + type args struct { + config Config + } + + tests := []struct { + name string + args args + want *exec.Cmd + }{ + { + "default", + args{config: Config{}}, + exec.Command("terraform", "apply", "plan.tfout"), + }, + { + "with targets", + args{config: Config{Targets: []string{"target1", "target2"}}}, + exec.Command("terraform", "apply", "--target", "target1", "--target", "target2", "plan.tfout"), + }, + { + "with parallelism", + args{config: Config{Parallelism: 5}}, + exec.Command("terraform", "apply", "-parallelism=5", "plan.tfout"), + }, + } + + for _, tt := range tests { + g.Assert(tfApply(tt.args.config)).Equal(tt.want) + } + }) + }) + + g.Describe("tfDestroy", func() { + g.It("Should return correct destroy commands given the arguments", func() { + type args struct { + config Config + } + + tests := []struct { + name string + args args + want *exec.Cmd + }{ + { + "default", + args{config: Config{}}, + exec.Command("terraform", "destroy", "-force"), + }, + { + "with targets", + args{config: Config{Targets: []string{"target1", "target2"}}}, + exec.Command("terraform", "destroy", "-target=target1", "-target=target2", "-force"), + }, + { + "with parallelism", + args{config: Config{Parallelism: 5}}, + exec.Command("terraform", "destroy", "-parallelism=5", "-force"), + }, + } + + for _, tt := range tests { + g.Assert(tfDestroy(tt.args.config)).Equal(tt.want) + } + }) + }) + + g.Describe("tfPlan", func() { + g.It("Should return correct plan commands given the arguments", func() { + type args struct { + config Config + } + + tests := []struct { + name string + args args + destroy bool + want *exec.Cmd + }{ + { + "default", + args{config: Config{}}, + false, + exec.Command("terraform", "plan", "-out=plan.tfout"), + }, + { + "destroy", + args{config: Config{}}, + true, + exec.Command("terraform", "plan", "-destroy"), + }, + } + + for _, tt := range tests { + g.Assert(tfPlan(tt.args.config, tt.destroy)).Equal(tt.want) + } + }) + }) } From 42a10997d589c8ff665a902c7a9dbd78fbf55c4a Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 09:59:18 -0600 Subject: [PATCH 06/10] Add a valid action to error message --- plugin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 5699203..1da7b02 100644 --- a/plugin.go +++ b/plugin.go @@ -91,7 +91,7 @@ func (p Plugin) Exec() error { commands = append(commands, tfPlan(p.Config, true)) commands = append(commands, tfDestroy(p.Config)) default: - return fmt.Errorf("valid actions are: validate, plan, apply, destroy. You provided %s", action) + return fmt.Errorf("valid actions are: validate, plan, apply, plan-destroy, destroy. You provided %s", action) } } From 12ce935ca768b586189e499cc3859177fd4293f5 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 10:01:00 -0600 Subject: [PATCH 07/10] Version bump golang 1.9 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 49045d3..94354d8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,7 +4,7 @@ workspace: pipeline: test: - image: golang:1.8 + image: golang:1.9 environment: - CGO_ENABLED=0 commands: From 77bd39b3efa3576a18f00129bfa7e4a51e8fef03 Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 10:06:42 -0600 Subject: [PATCH 08/10] Formatting --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7c376e0..dbcfadb 100644 --- a/main.go +++ b/main.go @@ -122,7 +122,7 @@ func run(c *cli.Context) error { plugin := Plugin{ Config: Config{ - Actions: c.StringSlice("actions"), + Actions: c.StringSlice("actions"), Vars: vars, Secrets: secrets, InitOptions: initOptions, From feef3866dfcdc04b4a96aef6c9a6eea4816bfdbc Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 10:16:14 -0600 Subject: [PATCH 09/10] Remove forcing a call on plan with apply or destroy actions --- plugin.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin.go b/plugin.go index 1da7b02..ff5c526 100644 --- a/plugin.go +++ b/plugin.go @@ -85,10 +85,8 @@ func (p Plugin) Exec() error { case "plan-destroy": commands = append(commands, tfPlan(p.Config, true)) case "apply": - commands = append(commands, tfPlan(p.Config, false)) commands = append(commands, tfApply(p.Config)) case "destroy": - commands = append(commands, tfPlan(p.Config, true)) commands = append(commands, tfDestroy(p.Config)) default: return fmt.Errorf("valid actions are: validate, plan, apply, plan-destroy, destroy. You provided %s", action) From a4d1880e41fc4cfedc47ca33f3f64ace2a0cc4cb Mon Sep 17 00:00:00 2001 From: Jacob McCann Date: Wed, 14 Feb 2018 10:47:32 -0600 Subject: [PATCH 10/10] Update default actions to include plan --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index dbcfadb..c513590 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ func main() { Name: "actions", Usage: "a list of actions to have terraform perform", EnvVar: "PLUGIN_ACTIONS", - Value: &cli.StringSlice{"validate", "apply"}, + Value: &cli.StringSlice{"validate", "plan", "apply"}, }, cli.StringFlag{ Name: "ca_cert",