Ask Your Question
0

What is the process of segregating environments using the `main` module approach in Terraform?

asked 2021-04-19 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-06-19 19:00:00 +0000

nofretete gravatar image

The process of segregating environments using the main module approach in Terraform involves creating a separate Terraform configuration file for each environment (e.g. staging, production, etc.) and storing them in separate directories.

Each environment configuration file (main.tf) should define the resources and modules specific to that particular environment. However, to ensure consistency across environments, a main module can be created to house common resources and modules that are shared across all environments.

The main module should be defined in a separate directory that is outside of the environment-specific directories. The environment directories should reference the main module using a module block in the respective main.tf files.

For example, the directory structure might look like:

main-module/
└── main.tf
staging/
└── main.tf
production/
└── main.tf

Then, the main.tf file in the staging directory would declare the main module as follows:

module "main" {
  source = "../main-module"
}

And the main.tf file in the production directory would do the same:

module "main" {
  source = "../main-module"
}

This helps to ensure consistency across environments by sharing common resources and modules while still allowing for environment-specific configuration.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-19 11:00:00 +0000

Seen: 9 times

Last updated: Jun 19 '22