Reorganization of terraform/terragrunt code to make it more scalable
We've created a terraform repo that deploys a Fargate based ECS with an ALB, VPM and routes. The main terraform folder contains 6 modules We have the main file that allows us to deploy the `6 modules`. So with a simple `terraform apply` everything is deployed (around 35 resources). Furthermore, we have implemented terragrunt to keep things `DRY` between environments. The main repo looks like this: ``` terraform_modules/ cloudwatch/ ecs/ iam/ lb/ route53/ vpc/ main.tf variables.tf environments/ dev/ terragrunt.hcl staging/ production/ ```` the `terragrunt.hcl` file looks as follows: ``` terraform { source = "../..//terraform_modules/" } inputs = { AWS_REGION = get_env("AWS_REGION") AWS_ACCES_KEY = get_env("AWS_ACCESS_KEY") AWS_SECRET_KEY = get_env("AWS_SECRET_KEY") } ``` Main questions: - From the book `Terraform up& running - O'Reilly` it looks like it's not good practice to deploy everything from a single command, since I'll be dealing with more than 35 resources at once. What would be the best recommendations? - Should I deploy resources from the modules folder and create a readme with instruction on the modules deployment order? - If so, should I replace from `variables` in each module to `data` ? - Terragrunt organization: - from the documentation, it looks like i should refactor as well my single terragrunt to split it into multiple terragrunts. For my given config, should I do that? Thanks in advance, --- <ins datetime="2022-05-31T14:56:04Z"> <p><a href="https://support.gruntwork.io/hc/requests/108682">Tracked in ticket #108682</a></p> </ins>
Hi, I believe this is touching on the question of how granular your infrastructure modules should be (as in, when is a module too "big"). If so, then I believe the answers to this knowledge base post should help: https://github.com/gruntwork-io/knowledge-base/discussions/402 Once you have figured out how you want to componentize your modules, then you can start thinking about how to handle deployment order and dependency management, in which case Terragrunt `dependency` blocks will come into play. Refer to the [terragrunt docs on working with multiple modules](https://terragrunt.gruntwork.io/docs/features/execute-terraform-commands-on-multiple-modules-at-once/) for more info on what Terragrunt offers to help with this. One thing to be aware of though is that if you really do want to deploy and manage all your infrastructure as one unit (that is, you don't think the risks of managing all the components together are worth the cost of breaking it apart), then you should NOT transition away from your current implementation. Multi module/state management adds a lot of overhead and you lose some niceties like having access to a global plan (see [this comment](https://github.com/gruntwork-io/terragrunt/issues/720#issuecomment-497888756)). In other words, if you want to, or see a need to, manage your environments as one unit, then it is perfectly fine to keep what you have.