You could possibly do things with multiple providers and setting the alias and profile fields in provider.tf
Don’t think it’s possible to use different backends in different accounts. AFAIK, the alias field doesn’t exist for a terraform backend config. So, the backend would be shared. So don’t think it’s even possible in one-go with Terraform. It’s also coupled.
Believe it’s cleaner via a wrapper script. At least that’s my 2 cents. The infrastructure code would be the same. The difference would be TS_ENV. Example:
#!/bin/bash
for i in dev prod uat qa stag; do
TS_ENV=$i terraspace up demo -y
done
Sometimes, folks tend to try to fit everything into one tool to come up with a “god” command. It may be impossible to ever fit the god criteria. As the linux saying goes, “Use the right tool for the right job”. Did an interview with Anton B, he explains it pretty clearly: “We still have makefiles, we still have shell”. Here’s the video at the specific time: https://youtu.be/J_-XPfFlsbU?t=6420 Also see: Customized layering support?
Also think it’s probably better to have different CI jobs on the separate AWS accounts to run terraspace up
. It’s nice and secure to separate the machine that handles each environment’s deployment. To keep the CI setup itself DRY, could use terraspace to build the CI jobs themselves. Or could use something like https://cody.run/ to build the CI setup with code. Note, am author of the cody tool also. Cody has similar patterns where you can use the same infrastructure code to build multiple permutations.