I am going to be managing the CDN configurations of dozens of applications through Terraform. I have a set of .tf
files holding all the default constant settings that are common among all configurations and then each application has its own .tfvars
file to hold its unique settings.
If I run something like terraform apply --var-file=app1.tfvars --var-file=app2.tfvars --var-file=app3.tfvars
then only the last file passed in is used.
Even if this did work it will become unmanageable when I extend this to more sites.
What is the correct way to incorporate multiple .tfvars
files that populate a common set of .tf
files?
Edit: I should add that the .tfvar
files define the same variables but with different values. I need to declare state of the resources defined in the .tf
files once for each .tfvar
file.
I found the best way to handle this case (without any 3rd party tools is to use) Terraform workspaces and create a separate workspace for each .tfvars
file. This way I can use the same common .tf
files and simply swap to a different workspace with terraform workspace select <workspace name>
before running terraform apply --var-file=<filename>
with each individual .tfvars
file.
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