'Wrapping your terraform root modules in another module
Is it a bad practice to wrap your terraform root modules (dir where you run terraform plan) in another module?
for example:
dev/base
main.tf
dev/databases
main.tf
dev/base/main.tf
module "data-science" { << inside this module i would setup s3 buckets, iam roles, etc with publicly available tf modules
...
...
}
dev/databases/main.tf
module "databases" { << inside this module i would setup mysql, postgres with publicly available tf modules
...
...
}
My reason for this is that I would like to be able to create other environments with as little copying/pasting/modifying of the root modules code as much as possible, wrapping the contents of each root module in another module seems to keep this as dry as possible.
Is this a good/bad idea?
Update:
To clarify, this what what I may see this in a root module
dev/main.tf
module "ec2-instance" {
cpu = 1
mem = 1
}
module "iam-role" {
}
module "security-group" {
}
data "iam-policy {
}
You often times end up with multiple modules, data sources, etc. this could grow large.
Say I want to replicate this setup in another environment. I end up copying dev/main.tf to another environment and just searching through the main.tf and making modifications to things to make it fit the environment.
to keep it more dry and more easily deployable, would this make sense. wrapping all the modules above into a parent module.
dev/main.tf
module "my-root-module-wrapper" {
ec2_cpu = 1
ec2_cpu = 2
}
Now if I want to deploy my a new environment, i'm just copying the calling of my root module wrapper that calls all the other terraform. this seems cleaner.
Thought is that all terraform that would otherwise go into a root module instead should now go in "my-root-module-wrapper" instead. making it easier and more DRY to deploy to different environments.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
