mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
feat(terraformExecute): pass global options to terraform (#3220)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
parent
9a60143153
commit
e041f84f2f
@ -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
|
||||
|
@ -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{},
|
||||
|
@ -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 {
|
||||
|
@ -23,6 +23,12 @@ spec:
|
||||
- type: vaultSecretFile
|
||||
name: terraformExecuteFileVaultSecret
|
||||
default: terraformExecute
|
||||
- name: globalOptions
|
||||
type: "[]string"
|
||||
scope:
|
||||
- PARAMETERS
|
||||
- STAGES
|
||||
- STEPS
|
||||
- name: additionalArgs
|
||||
type: "[]string"
|
||||
scope:
|
||||
|
Loading…
Reference in New Issue
Block a user