'Advices on how structure large Terraform projects

I am using Terraform since 2017 and I usually create cloud resources with this simple but effective scheme (called hereafter approach-1):

1 company project == 1 Terraform project == 1 folder in git repo == 1 Azure resource group

It works perfectly for a lot of cases, especially if the number of resources is not very large and all resources are tight together.

For complex projects, though, this doesn't work very well. I don't want to use the approach-1 for two reasons:

  • having a lot of resources and variety in the same Azure resource groups makes the navigation inside (through Azure portal) quite confusing
  • having a single Terraform project it scares me a little bit as if I made a config mistake I could do a large damage.

Then I go with approach-2:

1 company project == N Terraform projects (1 for each "component") == N folders in git repo == N Azure resource groups.

But it is not a piece of cake as there are other issues:

  • variables dependency among components: I am using Azure Keyvault as a way to pass "global variables" but again is not super convenient as if I make a change in one of the component that shares a global variable, I need to update all the components that uses such variable.
  • issues in case of destroying resources: if I have a TF project that creates the API gateway and another that manage an Azure function app + the API policy for that Azure function app, I need to remember to destroy the function app before the API gateway.

I also tried to use modules but I don't think that solve the issue.

What is your experience on that? Any thought? Thank you very much!

I tried approach-1 and approach-2 but without satisfying results.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source