deliveredtechnologies / terraform-maven

Terraform Maven Plugin
Apache License 2.0
42 stars 13 forks source link

Variable declaration breaks command execution on Windows #193

Open StevenKGER opened 4 years ago

StevenKGER commented 4 years ago

Hi,

when applying a Terraform stack (with class TerraformApply from tf-cmd-api) the variable declaration with ' breaks the command execution.

org.zeroturnaround.exec.InvalidExitValueException: Unexpected exit value: 1, allowed exit values: [0], executed command [cmd.exe, /c, terraform apply -var 'bucket_name=mysupernicebucket' -auto-approve ] in directory ... was 332 bytes:
[0mvar.bucket_name
  Enter a value: 

Error: Value for undeclared variable

A variable named "'bucket_name" was assigned on the command line, but the root
module does not declare a variable of that name. To use this value, add a
"variable" block to the configuration.

In this case the variable is read as 'bucket_name with the leading char '.

Tryting to patch https://github.com/deliveredtechnologies/terraform-maven/blob/2418c58a3cb3fbe2da460e37f554802c25e8a2c4/tf-build-tools/tf-cmd-api/src/main/java/com/deliveredtechnologies/terraform/api/TerraformApply.java#L109 to

options.append(String.format("-%1$s \"%2$s\" ", param, var.trim()));

worked for me on Windows. However I'm not able to test if it will work on Linux/MacOS/... too.

I didn't test it, but I think, the problem will also occur in https://github.com/deliveredtechnologies/terraform-maven/blob/2418c58a3cb3fbe2da460e37f554802c25e8a2c4/tf-build-tools/tf-cmd-api/src/main/java/com/deliveredtechnologies/terraform/api/TerraformDestroy.java#L107

TerraformPlan, ...

Clayton7510 commented 4 years ago

The recommended approach for Windows is using GitBash and setting the SHELL_PATH environment variable as specified in the README.md doc. There is a known bug in Terraform 0.12+ that causes an additional ' character to be added. Additionally, the execution of Terraform was streamlined in a previous release. Please confirm that this is still an issue. Apologies for the delayed response.

StevenKGER commented 4 years ago

Hi!

There is a known bug in Terraform 0.12+ that causes an additional ' character to be added. Additionally, the execution of Terraform was streamlined in a previous release.

Yes, the problem seems to be solved (tested it with Terraform 0.13.3).