How to Create Terraform Multiple Environments
Origin article
How to Create Terraform Multiple Environments by Guillaume Vincent
https://getbetterdevops.io/terraform-create-infrastructure-in-multiple-environments/
Main Issue: The main issue is how to factorize the code as much as possible to adhere to the "Don't Repeat Yourself" (DRY) principle when using Terraform to create infrastructure in multiple environments, regions, or cloud providers.
Bullet Points:
The challenge is to create multiple environments in code while minimizing code duplication.Two strategies are presented:Both strategies have their strengths and weaknesses, and the choice depends on project expectations and requirements.Other solutions can be used to compensate for the shortcomings, such as implementing a continuous deployment pipeline or generating environment creation through templating.It's important to consider scalability, the pace of environment creation, file isolation, and the workspace abstraction mechanism when deciding on an approach.My thinking:
The Workspaces approach is preferred as it provides better scalability and allows for quicker environment creation.By utilizing workspaces, errors can be reduced through proper workspace selection and continuous deployment pipelines.Customization of environment layers may be less obvious in the Workspaces approach compared to the Separated directories approach.Additional solutions, such as templating, can be implemented to address any shortcomings of the chosen approach.Keywords:
Terraform (Terraform is a tool for infrastructure provisioning and management.)Multiple Environments (Creating and managing different environments for development, staging, and production.)Infrastructure as Code (Managing infrastructure through code and version control.)DRY Principle (Don't Repeat Yourself principle in software development.)Workspaces (Managing multiple states in Terraform using workspaces.)