JohnDu17
JohnDu17

Reputation: 57

Terraform : manage specificities over each environment

I have 3 environments to manage via Terraform: dev, staging, prod.

An example of use case is below:

How can I easily manage common & specific resources for each environment?

Terraform is very simple if all environments are equals, but for specificities it looks more complicated. The goal is have a structural way to manage it, and then to avoid:

It should be possible for Terraform to look into current root folder UNION dev/staging/prod folder (depending on the environment).

The need is very simple but implementation seems so difficult.

Thanks for help ! :)

Upvotes: 0

Views: 635

Answers (2)

Martin Atkins
Martin Atkins

Reputation: 74594

This is a pretty broad question and so it's hard to answer specifically, but one general answer to this question is to make use of shared modules as a means for sharing code between your separate configurations.

The Module Composition guide describes some different patterns that might help you in your goal. The idea would be to make each of your configurations share modules wherever it makes sense for them to do so but to also potentially use different modules -- or the same modules but with different relationships/cardinalities -- so that your configurations can represent both what is the same and what is different between each of them.

Upvotes: 1

Marcin
Marcin

Reputation: 238707

One way would be to put shared resources in a common configuration managed in a remote state. Then in other configurations, you can refer to the shared, remote state using terraform_remote_state data source.

Upvotes: 0

Related Questions