Terraform Kubernetes service definitions in individual git repositories?

9/14/2020

Is there a recommended pattern or solution for keeping the definitions of individual Terraform services in their respective code repositories while still being able to update the entire project's infrastructure at once?

We're migrating to GCP from a managed service and already use Github+Actions.

I was thinking of doing this a couple different ways, either through private Terraform Modules on GCS or using git submodules.

While we could use a single central repository for all Terraform files, I would prefer that service definitions live in their respective repositories so as to avoid mistakes and not have future contributors overlook modifying service definitions where appropriate.

-- crockpotveggies
git
kubernetes
terraform

1 Answer

9/15/2020

Take a look at Terragrunt: https://terragrunt.gruntwork.io/

When declaring a terraform block, a source arg can be a link to a different git repo https://terragrunt.gruntwork.io/docs/features/keep-your-terraform-code-dry/#remote-terraform-configurations

To update the entire project at once, there's terragrunt plan-all, terragrunt apply-all, and very handy terragrunt graph-dependencies.

Gruntwork (the org that built this) has a set of free modules https://github.com/gruntwork-io/, a set of paid modules (monthly subscription), and of course, you can use your own modules.

-- Max Lobur
Source: StackOverflow