terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Plan only on changed modules

Open monegim opened this issue 2 years ago • 5 comments

According to the docs, when the command

terragrunt run-all plan

is applied,

This will recursively search the current working directory for any folders that contain Terragrunt modules and run plan in each one, concurrently, while respecting ordering defined via dependency and dependencies blocks. Describe alternatives you've considered

As plan on large infrastructures could be costly, Is there a way to plan only on the changed modules.

monegim avatar Sep 24 '23 08:09 monegim

As far as I know the best way is outlined in this document.

https://terragrunt.gruntwork.io/docs/features/keep-your-terragrunt-architecture-dry/#considerations-for-cicd-pipelines

You'd use git-diff to collect all changed files in a PR, and run terragrunt plan on each one using -terragrunt-config in a CI script.

RyanBaker19 avatar Sep 28 '23 18:09 RyanBaker19

I'd love for this kind of "change detection" to be incorporated into terragrunt itself. Something based on a "git committish", e.g. git diff --name-only {{ COMMITISH }}. A commitish is something like 1.0.0...HEAD, and when passed to git diff --name-only, would list all the files changed between the branch HEAD and the 1.0.0 ref/tag. Terragrunt would then have some logic to walk the dependency tree and note which "included" working-dirs would be impacted by any of those changed files and filter in only those things impacted (or filter out and exclude, depending on perspective)...

lorengordon avatar Sep 28 '23 18:09 lorengordon

We use Terramate in our Terragrunt repos to add change detection. E.g., instead of terragrunt apply-all we run terramate run --changed -- terragrunt apply, which runs the apply command on changed modules only.

What I like about Terramate is that it can be onboarded to any Terragrunt repository with a single command and without introducing any changes to our code. The team over at Terramate came up with an example also: https://github.com/terramate-io/terramate-terragrunt-infrastructure-live-example

carpetgoat avatar Mar 27 '24 15:03 carpetgoat

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.

github-actions[bot] avatar Sep 29 '24 02:09 github-actions[bot]

Bad stalebot. You're dismissed.

lorengordon avatar Sep 29 '24 02:09 lorengordon