0
0
mirror of https://github.com/thegeeklab/wp-opentofu.git synced 2024-11-24 23:30:39 +00:00

refactor generating args for vars and var-files

This commit is contained in:
Jacob McCann 2018-07-31 13:53:20 -05:00
parent 4858bea4e6
commit d11ee9dc0a

View File

@ -256,12 +256,8 @@ func tfDestroy(config Config) *exec.Cmd {
for _, v := range config.Targets { for _, v := range config.Targets {
args = append(args, fmt.Sprintf("-target=%s", v)) args = append(args, fmt.Sprintf("-target=%s", v))
} }
for _, v := range config.VarFiles { args = append(args, varFiles(config.VarFiles)...)
args = append(args, fmt.Sprintf("-var-file=%s", v)) args = append(args, vars(config.Vars)...)
}
for k, v := range config.Vars {
args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
}
if config.Parallelism > 0 { if config.Parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism))
} }
@ -292,12 +288,8 @@ func tfPlan(config Config, destroy bool) *exec.Cmd {
for _, v := range config.Targets { for _, v := range config.Targets {
args = append(args, "--target", fmt.Sprintf("%s", v)) args = append(args, "--target", fmt.Sprintf("%s", v))
} }
for _, v := range config.VarFiles { args = append(args, varFiles(config.VarFiles)...)
args = append(args, fmt.Sprintf("-var-file=%s", v)) args = append(args, vars(config.Vars)...)
}
for k, v := range config.Vars {
args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
}
if config.Parallelism > 0 { if config.Parallelism > 0 {
args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism)) args = append(args, fmt.Sprintf("-parallelism=%d", config.Parallelism))
} }
@ -329,6 +321,22 @@ func tfValidate(config Config) *exec.Cmd {
) )
} }
func vars(vs map[string]string) []string {
var args []string
for k, v := range vs {
args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
}
return args
}
func varFiles(vfs []string) []string {
var args []string
for _, v := range vfs {
args = append(args, fmt.Sprintf("-var-file=%s", v))
}
return args
}
// helper function to write a netrc file. // helper function to write a netrc file.
// The following code comes from the official Git plugin for Drone: // The following code comes from the official Git plugin for Drone:
// https://github.com/drone-plugins/drone-git/blob/8386effd2fe8c8695cf979427f8e1762bd805192/utils.go#L43-L68 // https://github.com/drone-plugins/drone-git/blob/8386effd2fe8c8695cf979427f8e1762bd805192/utils.go#L43-L68