Make Terraform code dry - 30+ different configurations

Hi everyone,
I hope TF expert can help with a possible solution. I’m using Terraform to deploy the same application/infrastructure of microservice to multiple AWS accounts (sandbox and prod) whenever we get a new client.

Currently, it’s not easy to maintain Terraform code because we’re using the Github repository and branches for every microservice deployment. For every microservice, we have Github Repository, and inside that repository branches for every client. So for the service X I have 1 Github Repo and 20 branches(sandbox and prod) for 10 clients. If we make Terraform infrastructure change then it means I need to update all 20 branches. It’s not easy to manage and have consistent infra.

I imagine having one microservice X Terraform codebase where we call all necessary modules to create Infra, and it will be easy to manage since there’s only one main codebase for every client. Then in order to customize infra per client/stack like EC2 type, different naming, domains, spec etc. maybe somehow terraform.tfvars could be used, or to version tfvars file per client ?

Does anyone have a solution how to make this simple and easy to maintain ? Maybe to use Terragrunt as a wrapper ?
I’m also planning to switch to the Terraform Cloud.

Thanks in advance, cheers.

Hi, you probably need the X TF codebase to be in a separate repo, for which you will reference from the TF scripts of each of your client.

A good read here Promote immutable, versioned Terraform modules across environments