terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

`terragrunt stack clean` removes local statefiles

Open mhulscher opened this issue 11 months ago • 2 comments

$ terragrunt --version
terragrunt version v0.78.0

When using local statefiles, the terragrunt stack clean command removes the entire .terragrunt-stack directory structure, including all state files. I use local statefiles when testing my iac components. I can't clean the generated directory structure without first running tf destroy.

I open this issue more as a question of "is this desirable or not?".

mhulscher avatar May 07 '25 09:05 mhulscher

Hey @mhulscher ,

Yes, it's intended. Is there alternate behavior that's preferred?

yhakbar avatar May 07 '25 11:05 yhakbar

@yhakbar I would prefer if the clean command only removed files (not directories) that were generated by terragrunt. So if I refactor my terragrunt.stack.hcl to rename a unit or stack, I would like clean to remove those directories' terragrunt.hcl, but not necessarily their state.

Right now, there doesn't seem to be a way to iteratively generate the unit tree, except for running clean followed by generate.

When doing local development, I tend to update my root terragrunt.stack.hcl quite a bit, followed by running terragrunt stack generate, and without running clean first, generate leaves lingering units that may have been removed or renamed.

mhulscher avatar May 13 '25 10:05 mhulscher

@mhulscher ,

That really isn't in the design of how Stacks were intended to function. The .terragrunt-stack directory is intended to be OK to fully regenerate on-demand based on a terragrunt.stack.hcl file. I think we can improve our documentation to help users mitigate issues related to loosing local state files from regeneration of .terragrunt-stack directories, but it's not going to involve selectively avoiding removal of state files.

yhakbar avatar Jun 26 '25 15:06 yhakbar

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 26 '25 02:09 github-actions[bot]