terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt destroy takes very long becuase of git show-toplevel

Open dustyhorizon opened this issue 1 year ago • 4 comments

Hello,

I have a monorepo with several terragrunt deployments. When I want to destroy a specific terragrunt resource via terragrunt destroy, terragrunt takes a very long time to resolve for affected dependencies to destroy because it crawls for affected dependencies via git rev-parse --show-toplevel. This makes a simple resource destruction take ~10mins which is a really long time.

Is there a smarter way to do this? Maybe by specifying a boundary of which to crawl for dependencies?

dustyhorizon avatar Apr 02 '23 06:04 dustyhorizon

We also affected by terragrunt destroy takes long time issue, terragrunt apply is not affected and is near instant.

terragrunt version 0.51.6

When running terragrunt destroy --terragrunt-log-level debug we can see that terragrunt goes through every child directory in the repo and evaluates locals, which takes time.

We are not using dependencies much, and as a workardound, we've done the following:

mkdir $REPO_ROOT/0-terragrunt-destroy-workaround
tee $REPO_ROOT/0-terragrunt-destroy-workaround/terragrunt.hcl <<EOF >/dev/null
locals {
  raise = get_env("DOES_NOT_EXIST")
}
EOF

The workaround causes terragrunt to fail early the "evaluate all locals" stage, but doesn't seem to affect destroy/apply commands and it's working fine from what we can tell.

Why terragrunt tries to evaluate all locals in every child directory when doing destroy even when no dependencies are used?

pbnsh avatar Sep 29 '23 13:09 pbnsh

We've just moved to terraform 1.6.2 and terragrunt 0.52.5 and terragrunt destroy actions now take 30mins or more. We use a mono-repo for a 'controlplane layer' and having a destroy action evaluate everything takes an age.

EDIT: Seems this is reported here also: https://github.com/gruntwork-io/terragrunt/issues/2201 That link has a workaround of using a plan to make the destroy phase specific. terragrunt plan -destroy -out tf.plan; terragrunt apply tf.plan

I've tracked this to v0.51.9. Behaviour for 0.51.8 is fine. @denis256, did the changes in https://github.com/gruntwork-io/terragrunt/pull/2740/files introduce this behaviour?

n00borama avatar Oct 26 '23 09:10 n00borama

Hitting the same issue as @n00borama , was updating our binaries and noticed that it was taking an excruciatingg amount of time. Even on the latest version so this is not fixed yet.. so will lock our version to 0.51.8 as well, which is working fine.

@denis256 this seems like a bit of a bug, any way to raise priority on this ? a normal destroy takes 2 mins for me, now its taking 45mins to traverse and check every single folder in my repo..

propyless avatar Feb 19 '24 11:02 propyless

Same issue here, destroying takes about 15 minutes before it even starts showing something. v0.52.5, not the most recent but I understand it isn't solved in the latest version anyways.

gercograndia avatar Mar 08 '24 15:03 gercograndia