Managing multiple environments in terraform

I have a repo and in the root I have three directories for qa, stage and prod for each environment to create infrastructure in respective environment.
And I want to keep the code DRY (Don’t repeat yourself).

NOTE: In each directory qa, stage and prod we are calling the child modules which are in the remote and not placing the child module configuration at the root of the module.

I have a providers.tf file which is a globally common where all the providers are defined and each have alias. But, I want to place the provideres.tf file in the root of the repo instead of placing the SAME file in all the three qa, stage and prod directories.

Is it possible to place the common globally defined Providers.tf file in the root of the repo and build the infrastructure in all the environments? Also, we are trying to stick with the vanilla terraform instead using the terragrunt. Is it possible?

I typically use symlinks to solve this problem, and have had a lot of success in doing so. They work really well.
Create your Providers.tf file in the root of the repo and then symlink it into each directory

# cd to root of your repo
ln -s Providers.tf qa/Providers.tf
ln -s Providers.tf stage/Providers.tf
ln -s Providers.tf prod/Providers.tf

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.