Comparing Options for Handling Environment Config in Terraform and remaining DRY

There are multiple ways to configure environment settings in Terraform. This repo evaluates initial four but it has branched out to multiple possible methods with an aim of writing DRY easy to maintain code.

Example Solution Requirements

  • 1 solution consisting of EC2 web frontend connecting to RDS Postgres backend and an S3 bucket
  • 4 environments in main region and a DR in a different region
  • The Prod S3 bucket must have 90 day lifecycle policy wheras it's not required on non-prod
  • Resources tagged to easily identify different environments

Comparisons

Option 1: Terrafrom TFVars

Option 2: Terraform Workspaces

Option 2b: Terraform Workspaces with autovars

Option 3: Terragrunt

Option 3b: Terragrunt with simplified folder structure and environment config

Option 3c: Terragrunt with bash support and env var usage

Option 3d: Terragrunt with centralised hcl module files

Option 4: Terragrunt and Ansible

Some Useful Links by Terragrunt

How to manage multiple environments with Terraform using workspaces

How to manage multiple environments with Terraform using branches

How to manage multiple environments with Terraform using Terragrunt