terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt destroy dependency check including outside configuration

Open jlepere-everlaw opened this issue 2 years ago • 6 comments

The purview of the feature added from https://github.com/gruntwork-io/terragrunt/issues/299 feels too broad. Do we really want to be checking every terragrunt.hcl file in the git repo when running destroy commands?

The issue I'm running into is that locals are being evaluated for every terragrunt.hcl file. For my configuration, this includes a run_cmd that calls a script to package terraform code into s3 and return the path to be used as the terraform source. It doesn't really make sense to do this for every terragrunt.hcl my organization has defined when trying to destroy a particular terragrunt module. Also, the run_cmds are failing because an environment variable the script depends on isn't set, for some reason, although it is set before calling terragrunt.

Would it be worth adding a way to skip this functionality by default? Maybe a configuration attribute to turn the functionality off or a cli option to turn it on if it's off by default?

jlepere-everlaw avatar Jul 18 '22 18:07 jlepere-everlaw

Hi, can be an option to add feature flags to change the default behavior

denis256 avatar Jul 19 '22 12:07 denis256

Facing a similar issue where a run_cmd command is executed for every project in a repo with a lot of projects. This really slows down the execution of the destroy command. Having a way to turn it off would be useful.

P.S. ended up doing terragrunt plan -destroy -out tf.plan; terragrunt apply tf.plan as a workaround.

velkovb avatar Apr 04 '23 11:04 velkovb

This is also an issue for us. In our case, we have separate directories for dev and prod environments and evaluating locals everywhere results in calls to an external service in the other environment which it doesn't have active credentials for.

We're using @velkovb 's workaround for now, but it would be good to be able to disable this behavior.

brokenintuition avatar Aug 02 '23 20:08 brokenintuition

Another workaround:

terragrunt apply -destroy

Somehow, there seems to be a difference.. It's not only a convenience alias as terragrunt destroy --help claims:

terragrunt destroy --help
Usage: terraform [global options] destroy [options]

Destroy Terraform-managed infrastructure.

This command is a convenience alias for: terraform apply -destroy

BenjaminHerbert avatar Nov 07 '23 16:11 BenjaminHerbert

Another workaround:

terragrunt apply -destroy

Somehow, there seems to be a difference.. It's not only a convenience alias as terragrunt destroy --help claims:

terragrunt destroy --help Usage: terraform [global options] destroy [options] Destroy Terraform-managed infrastructure. This command is a convenience alias for: terraform apply -destroy

Hi,

We have the same problem after migration from terragrunt version v0.36.1 to v0.53.2.

And can confirm that using terragrunt apply -destroy instead of terragrunt destroy solves it.

Also terragrunt destroy should be made to behave like terragrunt apply -destroy because otherwise it causes problems like the ones already described.

pteroctopus avatar Nov 15 '23 15:11 pteroctopus