Terragrunt: Repo Structure V3
Description:
This post builds on Terragrunt Repo Structure V1 by simply showing the pros/cons of embedding terraform files in the same structure as terragrunt files.
Note: You can see the code for this post on my Github repo. Github Actions are here.
To Resolve:
-
In this post I just want to show that it is possible but not recommended to put your terraform files in the same file structure as you terragrunt files.
-
Let’s discuss the pros of this approach:
- It is very noobie friendly. People don’t have to get confused with terragrunt stuff as they can clearly see that the deployment folder here contains terraform files specific to nonprod => hub => south central region. So it is easy to add a variable or a new resource that is scoped specifically to that area, no guess work involved.
-
Let’s discuss the cons of this approach:
- Main con is lots of duplication. It is highly unlikely that your infrastructure is unique at each and every level of your folder structure.
- For example, resources deployed in the
east
will be highly similar to those deployed in thesouth central us
- Nonprod and prod I can see separation needed, but that is covered in Terragrunt Repo Structure V2.
- What about between subscriptions? It shouldn’t matter what code is deployed between
hub
andspoke
subscriptions right? Remember that you can have a different repo with different state files that manage things in one subscription but not another, no need to have everything in one single repo with one giant statefile per environment/region/subscription though you could if you wanted.
-
For any excuse you can give to embed your terraform files in with your terragrunt files, you can still move them up to a different folder structure as discussed in Terragrunt Repo Structure V2.
-
For example, you could have:
-
./infra/nonprod/east
and then in your./infra-config/nonprod/hub/east/deployment/terragrunt.hcl
just point yoursource
to"${find_in_parent_folders("infra")}//nonprod//hub//east"
. Yes this would be a lot of duplication of folder structures, but at least your terragrunt and terraform files are separated.
-
Comments