Terragrunt architecture best practices? #402
-
|
I’m getting started with Terragrunt and want to make sure I have this conceptually right. It looks like we can only source a single module from, e.g. Having the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
The core of Terragrunt architecture is considering how you want to break apart the Terraform state. While Terraform is optimized for working with a single state file, Terragrunt supports breaking apart your Terraform state into multiple component infrastructure through it's many features like However, since Terragrunt ultimately relies on Terraform under the hood, it is limited by Terraform's ability to have a single root module, and that's why you still need to define a single Terraform module to act as the root module for Terragrunt to invoke at the folder level. The way we at Gruntwork think about this is to differentiate between Services and Modules (See our blog post on Modules, Services, and Architectures for more details). The Service module is an opinionated, specific way to deploy components that fit the needs of your organization, which is less reusable, but is designed to be directly deployed by Terragrunt. If you look at our Service module for the ASG (asg-service), you will see that it combines the Gruntwork modules to construct the deployable ASG unit. Given that, you should be striving for 2 links in your chain: Services and Modules. That is, when extending Gruntwork modules, it is oftentimes much better organizationally to extend them in the Service layer by combining Gruntwork modules with resources and modules to create the deployable unit, rather than extending Gruntwork modules to create more Modules. This should significantly help with the dependency management. |
Beta Was this translation helpful? Give feedback.
-
|
A side note: When thinking about what should go in the Services, you should also be thinking about the Terraform state file. In essence, each Service Terraform module will translate to a single Terraform state. Given that, it is oftentimes useful to think about splitting your Services based on how you want to split the Terraform state. I previously wrote about this in a Terragrunt issue, which I will copy here since it is still relevant: When it comes to componentization, the best thing that has worked for us is to base it on the reason why you want to break up your state file in the first place. In general, there are 3 key benefits to breaking up your state file:
On the other hand, breaking up state files adds a lot of complexity to the dependency management, and you lose the benefits of having reliable planning mechanisms. So you don't want to break it down too much. Given that, the following litmus test has worked well for us when it comes to breaking things up:
|
Beta Was this translation helpful? Give feedback.
The core of Terragrunt architecture is considering how you want to break apart the Terraform state. While Terraform is optimized for working with a single state file, Terragrunt supports breaking apart your Terraform state into multiple component infrastructure through it's many features like
dependency.However, since Terragrunt ultimately relies on Terraform under the hood, it is limited by Terraform's ability to have a single root module, and that's why you still need to define a single Terraform module to act as the root module for Terragrunt to invoke at the folder level.
The way we at Gruntwork think about this is to differentiate between Services and Modules (See our blog post on M…