terraform-google-modules/terraform-google-gcloud

terraform-google-gcloud does not run on Windows

matthewblain opened this issue · 4 comments

The terraform-google-gcloud module does not run on Windows due to a reliance on shell scripts.

Repro

Run, say, terraform plan for a config which uses terraform-google-gcloud.

Result

Error: failed to execute ".terraform/modules/my_rule/scripts/check_env.sh": fork/exec .terraform/modules/my_rule/scripts/check_env.sh: %1 is not a valid Win32 application.

Expected

Terraform to run the gcloud or other command specified in the Terraform config.

The documentation says the requirements are

  • Terraform v0.12
  • Terraform Provider for GCP plugin v2.0
  • curl

All of these run well on Windows, as does the gcloud command line tool.

Proof of concept

It appears to work with these tweaks to main.tf:

  • Commented out data.external.env_override, set download_override to "never" .
  • Changed the run_command local-exec command to be ${self.triggers.create_cmd_entrypoint} ${self.triggers.create_cmd_body}. That is, remove the 'temporary' path part, which caused the command to fail silently.

This demonstrates that the concept works fine on Windows, though of course these changes are not suitable to be committed.

Possible cross-platform fixes

I am a Terraform novice, so take these with a big grain of salt.

  • Instead of check_env shell script, use an env var called, say, TF_VAR_GCLOUD_TF_DOWNLOAD and read it from within Terraform, e.g. ${var.GCLOUD_TF_DOWNLOAD}
  • Instead of check_components shell script, always run gcloud components install.
  • Instead of modifying the path, use (and possibly rename) gcloud_bin_abs_path . Note that if the install cache isn't being used, this prefix would be the empty string "", to use the version on the existing path.

Another possibility would be to create .cmd files parallel to the .sh files.

Alternate or interim solution

Document that a sh interpreter is required.

Thanks for the feedback, unfortunately this a bit tricky. Most likely real Windows support will require separate .cmd files.

Instead of check_env shell script, use an env var called, say, TF_VAR_GCLOUD_TF_DOWNLOAD and read it from within Terraform, e.g. ${var.GCLOUD_TF_DOWNLOAD}

Unfortunately this only works if this module were your "root module." However this module is most commonly embedded inside other modules, in which case we don't have native access to Terraform environment variables.

Instead of check_components shell script, always run gcloud components install.

This ends up slowing down execution substantially and is something we'd definitely like to avoid.

Thanks for the response.

My use case is "develop and test to test project on windows" and "deploy to production with on linux", while others simultaneously develop and test on mac.

To address that use case, the tool doesn't even need to have install working at all on Windows, it's fine to say it's required beforehand. So it might simplify things if it detects the OS and disables install there.

Note that after further investigation, I probably don't need this module, so this is low priority to me, but it may be helpful to others.

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

I'd like this to be reopened as I encounter the exact same issue. Is there any no hacky way to get the module work on windows?