Is there any way (or workaround) to specify the working directory when running terraform apply or terraform plan ? For example :
terraform apply working_dir/vpc
terraform apply working_dir/dns
terraform apply working_dir/postgres
terraform apply working_dir/service-a
terraform apply working_dir/service-b
I know there's a target option where we can specify the resources to target. But here I need a folder to have more abstraction. The final goal is to be able to setup the infrastructure running the following commands :
make vpc
make dns
make postgres
make service-a
make service-b
These days you can also use global option -chdir: The chdir option instructs Terraform to change its working directory to the given directory before running the given subcommand.
Without a saved plan file, terraform apply supports all planning modes and planning options available for terraform plan . Planning Modes: These include -destroy , which creates a plan to destroy all remote objects, and -refresh-only , which creates a plan to update Terraform state and root module output values.
Running Terraform Apply in Automation In automation terraform apply can be run after the plan stage, passing in the plan output file. If there is no plan stage prior to the apply stage (not recommended), then the terraform apply -auto-approve option can be used.
These days you can also use global option -chdir:
The chdir option instructs Terraform to change its working directory to the given directory before running the given subcommand. This means that any files that Terraform would normally read or write in the current working directory will be read or written in the given directory instead.
For example:
terraform -chdir=environments/production apply
You can specify a plan or directory when issuing the apply
command. Your examples are valid apply commands.
Usage: terraform apply [options] [dir-or-plan]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With