terragrunt-atlantis-config
terragrunt-atlantis-config copied to clipboard
Grace handle of `/dev/null` when destroying modules
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.
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"
}
Huh, interesting. I'll give it a try!