How to Create Terraform Multiple Environments

Don’t repeat yourself (DRY) with Terraform to create your infrastructure in multiple environments/regions/cloud-providers

Guillaume Vincent
4 min readOct 3, 2021
Photo by Gaël Gaborel / Unsplash
Photo by Gaël Gaborel / Unsplash

Terraform has simplified the way we provision infrastructure in the cloud and manage it as code. But best practices like separating infrastructure into multiple environments ( staging/QA/production) don’t change. Maybe even depending on your business needs, you need to extend the infrastructure across multiple geographical areas. Maybe you are even thinking about adopting a multi-cloud strategy.

If you are in this situation this means that you need to be able to create multiple environments in your code. The challenge here is to factorize the code as much as possible to the DRY (Don’t Repeat Yourself) principle. There are many ways of achieving it using Terraform.

In this article, we will see two strategies for doing this with Terraform. Each has its strengths and weaknesses and we’ll compare them at the end. Let’s go!

2 Strategies to Create Multiple Environments

In both presented strategies, we’re using modules included in projects for convenience. They can be versioned in distinct GIT repositories. Each module is called in a specific…

--

--

Guillaume Vincent

🌟 Freelance DevOps Engineer & SRE. I simplify containerization, cloud, and automation with actionable tips. Follow for practical insights and tech trends!