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

Merge pull request #71 from luis-silva/master

Add var and var file to destroy operation
This commit is contained in:
Jacob McCann 2018-07-31 13:30:17 -05:00 committed by GitHub
commit 4d19229cd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View File

@ -255,6 +255,12 @@ 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, fmt.Sprintf("-var-file=%s", v))
}
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))
} }
@ -286,11 +292,10 @@ func tfPlan(config Config, destroy bool) *exec.Cmd {
args = append(args, "--target", fmt.Sprintf("%s", v)) args = append(args, "--target", fmt.Sprintf("%s", v))
} }
for _, v := range config.VarFiles { for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v)) args = append(args, fmt.Sprintf("-var-file=%s", v))
} }
for k, v := range config.Vars { for k, v := range config.Vars {
args = append(args, "-var") args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
args = append(args, 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))
@ -312,11 +317,10 @@ func tfValidate(config Config) *exec.Cmd {
"validate", "validate",
} }
for _, v := range config.VarFiles { for _, v := range config.VarFiles {
args = append(args, "-var-file", fmt.Sprintf("%s", v)) args = append(args, fmt.Sprintf("-var-file=%s", v))
} }
for k, v := range config.Vars { for k, v := range config.Vars {
args = append(args, "-var") args = append(args, "-var", fmt.Sprintf("%s=%s", k, v))
args = append(args, fmt.Sprintf("%s=%s", k, v))
} }
return exec.Command( return exec.Command(
"terraform", "terraform",

View File

@ -102,10 +102,10 @@ func TestPlugin(t *testing.T) {
} }
tests := []struct { tests := []struct {
name string name string
args args args args
destroy bool destroy bool
want *exec.Cmd want *exec.Cmd
}{ }{
{ {
"default", "default",

View File

@ -32,7 +32,7 @@ func downloadTerraform(version string) error {
func downloadFile(filepath string, url string) error { func downloadFile(filepath string, url string) error {
// Create the file // Create the file
out, err := os.Create(filepath) out, err := os.Create(filepath)
if err != nil { if err != nil {
return err return err
} }
defer out.Close() defer out.Close()
@ -46,7 +46,7 @@ func downloadFile(filepath string, url string) error {
// Writer the body to file // Writer the body to file
_, err = io.Copy(out, resp.Body) _, err = io.Copy(out, resp.Body)
if err != nil { if err != nil {
return err return err
} }