terragrunt-atlantis-config icon indicating copy to clipboard operation
terragrunt-atlantis-config copied to clipboard

Grace handle of `/dev/null` when destroying modules

Open darwin67 opened this issue 1 year ago • 2 comments

Hi, I realized that when attempting to delete a terragrunt module by setting the source to /dev/null, this script will fail with the following error.

Error: Failed to read module directory: Module directory /dev/null does not exist or cannot be read.

Which is not technically wrong since that is a black hole and you can't read from it.

The problem is, because terragrunt doesn't have a good way to detect destroy attempts when deleting a directory, we need to do this kind of hack. https://github.com/gruntwork-io/terragrunt/issues/433#issuecomment-1494905080

While uncommon, when I need to mass destroy resources with this method, atlantis.yaml can't be generated due to the previous error.

Would be nice if you could detect that it's targeting /dev/null and in those cases, maybe skip and move on?

Don't have specific solutions in mind so happy to get suggestions too.

darwin67 avatar Nov 22 '23 18:11 darwin67

Have you tried pointing the source to any other directory other than /dev/null? That should work. I use this to toggle deletion / destruction of a module, where get_path_to_repo_root() doesn't contain any TF module:

terraform {
  source = local.destroy ? "${get_path_to_repo_root()}" : "${get_path_to_repo_root()}//modules/my_module"
}

the-nando avatar Nov 30 '23 07:11 the-nando

Huh, interesting. I'll give it a try!

darwin67 avatar Dec 02 '23 22:12 darwin67