Layering Advice


I am looking for some advice on how to best handle the application of multiple tfvars file. I am using Terraspace to deploy repeatable infrastructure to AWS which mainly consists of EC2 instances. I use tfvars file to seperate each environment and structure them like this:

Screenshot 2024-01-04 at 12.43.54

If I make a change within my in order to get each environment to pick up the change, I have been running:

TS_ENV=api2 terraspace up eis_ec2_managedinfra_win

to deploy these changes against the infrastructure referenced in api2.tfvars. Then repeating that command, changing the TS_ENV for each tfvars and the more environments I add, the longer this is taking.

I am wondering if there is a way to iterate through all of the tfvars files one by one, applying the changes?

I’ve had a look at the layering documentation, but I’m struggling to work out if this applies to my use case as I’m not combining the environments, they are completely seperate from each other.

Is there a way to achieve what I want to achieve?



Wondering if TS_EXTRA might help here.

I had a look at this and tested it out, but it didn’t achieve what I wanted. When I ran:

TS_ENV=api2 TS_EXTRA=aws1 terraspace up eis_ec2_managedinfra_win

it tried to create a brand new set of resources, instead of updating those that already existed.

I was hoping it would work like terraspace all up does when multiple stacks are deployed.

For now, I’ve written a simple bash script to iterate through the tfvars folder and run TS_ENV= terraspace up eis_ec2_managedinfra_win replacing with the name of the tfvar file.

I see. Yeah. Terraspace all doesn’t know about TS_EXTRA. All loop is what I would go with also.