antonbabenko / terraform-best-practices

Terraform Best Practices free ebook translated into 🇬🇧🇦🇪🇧🇦🇧🇷🇫🇷🇬🇪🇩🇪🇬🇷🇮🇱🇮🇳🇮🇩🇮🇹🇯🇵🇰🇷🇵🇱🇷🇴🇨🇳🇪🇸🇹🇷🇺🇦🇵🇰
https://www.terraform-best-practices.com/
Other
2.07k stars 431 forks source link

Why having the exact copy of main files (main.tf) in two different folders (prod/stage) is the best practice? #23

Closed michaelsync closed 4 years ago

michaelsync commented 4 years ago

I am trying to find the best practice for the Terraform folder structure. I found this page https://www.terraform-best-practices.com/examples/terraform/medium-size-infrastructure.

But I don't understand why it's the best practice to have the exact copy of mains in two different folders (prod, stage). Maybe I might be missing something. Please let me know what I miss. Thanks.

antonbabenko commented 4 years ago

Hi @michaelsync !

main.tf is copied and modified in two different folders (prod, stage) because there is no better mechanism available in Terraform which allows keeping code DRY'er, and also that file may be different for various environments (eg, version of modules, inputs).

Such size of infrastructure often leads to introducing another higher-level orchestration tool (eg, terragrunt) where main.tf is simplified and less repetitive.