hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.7k stars 9.55k forks source link

Functionality similar to make's `-C` #20097

Open slavaaaaaaaaaa opened 5 years ago

slavaaaaaaaaaa commented 5 years ago

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:

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.

realytcracker commented 5 years ago

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

naftulikay commented 5 years ago

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

asciifaceman commented 5 years ago

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)

eXist-FraGGer commented 5 years ago

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

slavaaaaaaaaaa commented 5 years ago

@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.