Terraform: Functionality similar to make's `-C`

Created on 24 Jan 2019  路  5Comments  路  Source: hashicorp/terraform

Current Terraform Version

Terraform v0.11.11

Use-cases

It would be nice to be able to set working directory on all terraform commands. As I understand, this is available for apply but not terraform output, for example.

Attempted Solutions

terraform output gcp/staging/resource naturally does not work, because the expected argument is the name of the output, not the working directory.

My current solution is as follows:

  • terraform output is defined as a make target
  • I then execute make -C somewhere/ output from wherever I need to

Proposal

I propose a solution similar to that of make: e.g., make -C gcp/staging/resource pizza. This flag, -C, is to be available on all terraform commands and will set the working directory.

References

I apologize if a similar issue already exists, as I have not found any in my searches.

enhancement

All 5 comments

i would also love to see this enhancement in a future release.

I think that Terraform workspaces accomplish something similar but I have always just used a similar make system as in naftulikay/terrakang

This would at the very least bring more consistency to the terraform CLI, something it can control and not an inconsistency brought about due to the AWS API (such as tag vs tags)

If I understood correctly this issue - we do not have any problem with it.
You should use module

This can be used as follows

"tf-dev:plan": "cd ./infrastructure/development && terraform init -get=true && terraform plan -out=terraform.tfplan",
"tf-dev:apply": "cd ./infrastructure/development && terraform apply terraform.tfplan",

module

infrastructure

@eXist-FraGGer of course one can cd into the needed directory and cd out of it afterwards, but that is exactly why I'm requesting this feature: to avoid having to do that. These are extra steps that tend to cause issues in scripts - there's a reason Make supports this.

Was this page helpful?
0 / 5 - 0 ratings