Reputation: 9298
I understand that when I run terraform CLI within a directory, it takes all the terraform artifacts from the current directory.
Is it possible to have terraform apply and terraform plan to look for scripts in a directory other than current PWD such that I don't have to keep changing current directory?
Upvotes: 1
Views: 7229
Reputation: 74209
At the time I'm writing this, Terraform v0.14.0 is currently in release candidate and its final release is expected in the next few weeks.
That new version will introduce a new feature to allow requesting that Terraform switch directory itself before running any of its subcommands. For example:
terraform -chdir=subdirectory init
terraform -chdir=subdirectory apply
This is essentially the same as launching Terraform with the current working directory already set to the given subdirectory, but with two minor differences:
path.cwd
value to be the directory where Terraform was run from, rather than the subdirectory. As before, path.root
is the directory containing the root module, so both directories are available.Neither of these differences are usually significant for common Terraform use, so in most cases you can think of the -chdir=
option as having the same effect as switching into the target directlry using cd
first.
Upvotes: 6