Replies: 1 comment
-
Hey @hydridity , If it works for you and your team, it's valid! Based on what you've written so far, it seems like you've already looked at the following: They're the best examples for learning about the best practices Gruntwork recommends adopting when writing Terragrunt configurations. The one major thing that I don't see you doing that most users do is use path_relative_to_include for determination of the state key in your backend. That makes it relatively easy to add new Terragrunt units, as each Is there something about your configuration that you're particularly concerned about? |
Beta Was this translation helpful? Give feedback.
-
Greetings,
I have quite the dilemma extending my Terraform workflow with Terragrunt and I'd like to ask for help with nudging me in the right direction
Context and story
We've started adopting Hashicorp Vault and with our existing declarative gitops practices the only right path was to manage it with Terraform, I dont mean deployment but purely the settings (Policies, Secret Engines, Identity Groups, Auth Methods...) .
So I've started with simple Terraform repository that managed single instance of Vault with everything inside it, that has now outgrown beyond it's initial scope, we've switched to enterprise version and started utilizing namespaces.
Entire infrastructure is divided in the concept of nested stage/customer (stage = environment: dev/test/prod...) and each stage having customers (customers are common across the stages, tho it's better to think of it in terms of region or product), and so the namespaces in the Vault do mirror it, there is namespace for each stage, and each stage namespace has sub-namespace for customer
The Dilemma
Since I'm dealing with multiple environments that has common configuration:
Any of those are common resources shared, varying only in the variables, so my conclusion was to reach for Terragrunt.
Until now I've been thinking about the Terragrunt repo in the scope of this only application, I've setup structure of my Terragrunt project similarly as the terragrunt-live-repo example:
I'm using the _dev as alternative fot the _global structure, since the namespace for stage is standalone namespace that needs it's own configuration independent from the customer
The file stage.hcl just contains local variable stage="dev", and customer.hcl contains customer="customer1" so far.
Then in my root.hcl I'm sourcing those variables and building state name, link where to store the backend and also provider settings:
After that I've started modularizing the original Tarraform and adding the modules into Terragrunt for environment where I needed them:
With variable inputs and terraform source for the module in the final terragrunt.hcl.
But I've quickly realized the problem with this setup, if I add another module for different part of the configuration, each of the modules need to initialize it's own backend.
That is counterproductive(initializing the repo after clonning will be a pain) and I can imagine potential issues if all modules will use the same state since it does not make sense to split the states in this situation as most of the resources depends on each other (App Roles depend on policies, Auth engines depend on Identity groups...).
I think it's best to keep then in single state for the specific environment.
Which got me thinking, should I be considering the Terragrunt repo in more of a description of entire infrastructure stack and not just for the single application?
In a way that I'd keep the child module inside customer as whole application (vault in this case) that will have all the inputs for entire Terraform project and save it into application state, while separating the provider configuration from root.hcl to another folder per application I'd want to manage same way as the _envcommon is in the terragrunt-live-example is ?
So when I have another Terraform repository for Keycloak I could bring it as another child module for the environment and use the variables from the Terragrunt repository as common inputs for both application:
Is that a valid approach ?
Beta Was this translation helpful? Give feedback.
All reactions