Managing/Versioning configuration files for multiple AWS accounts

Hello,
I have a Terraform code for deploying 8 microservices, and every microservice Terraform has its own Git Repository. My plan is to create the following Terragrunt structure:

production
├── terragrunt.hcl
├── microservice1
│   └── terragrunt.hcl
├── microservice2
│   └── terragrunt.hcl
└── microservice3
    └── terragrunt.hcl
    ...

Based on this example from the microservice folder, I will call the microservices Git repositories which contain Terraform modules. Here you can find a diagram illustrating my idea SCREENSHOT
I’ll need to deploy microservices to 20+ customer AWS accounts so my question is:

  1. What would be the best way to manage specific Terragrunt configuration/variables per customer, because I will need to version that. For example, every infrastructure will have different instances spec, naming, and maybe I will not need to deploy all 8 microservices to every AWS account ?
    Is it a good idea to have a dedicated Git branch or Git repository per client/customer AWS account where I will only edit variables like naming, infra spec etc, or to keep configuration files inside the Terragrunt Git repository?

I want to keep my microservices infra TF code DRY as possible because I need to have consistent infra resources across multiple AWS accounts.
Since I will have multiple customer AWS accounts to deploy the same infra, I need the best approach for managing configuration files, so I can easily update it for maintenance or if I need to deploy additonal infra resources.

Any advice is welcome. Thanks.

Hi @GTRR

I would recommend creating a new terraform module that uses module for_each to enable or disable each service, and then have a single terragrunt.hcl call per customer to deploy the set of services.

For example, you can create a single terraform module that takes as inputs each services configuration:

variables.tf

variable "microservice1_config" {
  type = any
  default = null
}

variable "microservice2_config" {
  type = any
  default = null
}

# ... and so on ...

main.tf

module "microservice1" {
  count = var.microservice1_config != null ? 1 : 0
  inputA = var.microservice1_config.inputA
  inputB = var.microservice1_config.inputB
  inputC = var.microservice1_config.inputC
  # ... and so on ...
}

module "microservice2" {
  count = var.microservice2_config != null ? 1 : 0
  inputA = var.microservice2_config.inputA
  inputB = var.microservice2_config.inputB
  inputC = var.microservice2_config.inputC
  # ... and so on ...
}

# ... and so on ...

You can then deploy each customer using:

terragrunt.hcl

inputs = {
  microservice1_config = {
    inputA = "something for input A"
    inputB = 14
    # ... and so on ...
  }

  # Skip microservice2_config so it doesn't get deployed

  microservice3_config = {
    inputA = "something for input A"
    inputB = 14
    # ... and so on ...
  }

  # ... and so on ...
}

In terms of DRY, you have two options. You can either configure the defaults for the services directly in the terraform module, or alternatively you can leverage the new multiple includes feature to DRY up the common inputs across all customers.

Hope this helps!

Best regards,
Yori