mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-09 18:00:40 +00:00
refactor generating args for vars and var-files
This commit is contained in:
parent
4858bea4e6
commit
d11ee9dc0a
32
plugin.go
32
plugin.go
@ -256,12 +256,8 @@ func tfDestroy(config Config) *exec.Cmd {
|
||||
for _, v := range config.Targets {
|
||||
args = append(args, fmt.Sprintf("-target=%s", v))
|
||||
}
|
||||
for _, v := range config.VarFiles {
|
||||
args = append(args, fmt.Sprintf("-var-file=%s", v))
|
||||
}
|
||||
for k, v := range config.Vars {
|
||||
args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
args = append(args, varFiles(config.VarFiles)...)
|
||||
args = append(args, vars(config.Vars)...)
|
||||
if config.Parallelism > 0 {
|
||||
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 {
|
||||
args = append(args, "--target", fmt.Sprintf("%s", v))
|
||||
}
|
||||
for _, v := range config.VarFiles {
|
||||
args = append(args, fmt.Sprintf("-var-file=%s", v))
|
||||
}
|
||||
for k, v := range config.Vars {
|
||||
args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
|
||||
}
|
||||
args = append(args, varFiles(config.VarFiles)...)
|
||||
args = append(args, vars(config.Vars)...)
|
||||
if config.Parallelism > 0 {
|
||||
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.
|
||||
// The following code comes from the official Git plugin for Drone:
|
||||
// https://github.com/drone-plugins/drone-git/blob/8386effd2fe8c8695cf979427f8e1762bd805192/utils.go#L43-L68
|
||||
|
Loading…
Reference in New Issue
Block a user