diff --git a/cmd/terraformExecute.go b/cmd/terraformExecute.go index 2c44dc227..0fb66a4d0 100644 --- a/cmd/terraformExecute.go +++ b/cmd/terraformExecute.go @@ -54,6 +54,10 @@ func runTerraformExecute(config *terraformExecuteOptions, telemetryData *telemet args = append(args, config.AdditionalArgs...) } + if config.GlobalOptions != nil { + args = append(config.GlobalOptions, args...) + } + utils.RunExecutable("terraform", args...) return nil diff --git a/cmd/terraformExecute_generated.go b/cmd/terraformExecute_generated.go index d9b4b9028..4b910e55f 100644 --- a/cmd/terraformExecute_generated.go +++ b/cmd/terraformExecute_generated.go @@ -18,6 +18,7 @@ import ( type terraformExecuteOptions struct { Command string `json:"command,omitempty"` TerraformSecrets string `json:"terraformSecrets,omitempty"` + GlobalOptions []string `json:"globalOptions,omitempty"` AdditionalArgs []string `json:"additionalArgs,omitempty"` } @@ -107,6 +108,7 @@ func TerraformExecuteCommand() *cobra.Command { func addTerraformExecuteFlags(cmd *cobra.Command, stepConfig *terraformExecuteOptions) { cmd.Flags().StringVar(&stepConfig.Command, "command", `plan`, "") cmd.Flags().StringVar(&stepConfig.TerraformSecrets, "terraformSecrets", os.Getenv("PIPER_terraformSecrets"), "") + cmd.Flags().StringSliceVar(&stepConfig.GlobalOptions, "globalOptions", []string{}, "") cmd.Flags().StringSliceVar(&stepConfig.AdditionalArgs, "additionalArgs", []string{}, "") } @@ -146,6 +148,15 @@ func terraformExecuteMetadata() config.StepData { Aliases: []config.Alias{}, Default: os.Getenv("PIPER_terraformSecrets"), }, + { + Name: "globalOptions", + ResourceRef: []config.ResourceReference{}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, + Type: "[]string", + Mandatory: false, + Aliases: []config.Alias{}, + Default: []string{}, + }, { Name: "additionalArgs", ResourceRef: []config.ResourceReference{}, diff --git a/cmd/terraformExecute_test.go b/cmd/terraformExecute_test.go index 7a0bdceee..5fb9f6cb5 100644 --- a/cmd/terraformExecute_test.go +++ b/cmd/terraformExecute_test.go @@ -63,6 +63,14 @@ func TestRunTerraformExecute(t *testing.T) { AdditionalArgs: []string{"-arg1"}, }, []string{"apply", "-auto-approve", "-var-file=/tmp/test", "-arg1"}, }, + { + terraformExecuteOptions{ + Command: "apply", + TerraformSecrets: "/tmp/test", + AdditionalArgs: []string{"-arg1"}, + GlobalOptions: []string{"-chgdir=src"}, + }, []string{"-chgdir=src", "apply", "-auto-approve", "-var-file=/tmp/test", "-arg1"}, + }, } for i, test := range tt { diff --git a/resources/metadata/terraformExecute.yaml b/resources/metadata/terraformExecute.yaml index c30062c08..d53ed58fe 100644 --- a/resources/metadata/terraformExecute.yaml +++ b/resources/metadata/terraformExecute.yaml @@ -23,6 +23,12 @@ spec: - type: vaultSecretFile name: terraformExecuteFileVaultSecret default: terraformExecute + - name: globalOptions + type: "[]string" + scope: + - PARAMETERS + - STAGES + - STEPS - name: additionalArgs type: "[]string" scope: