How do I destroy a module that has errors?
I am trying to destroy a module, and am running into an error that is preventing me from destroy that appears to be a code issue. For example: ``` Error: Invalid index on .terraform/modules/server/modules/single-server/outputs.tf line 10, in output "public_ip": 10: value = var.attach_eip ? aws_eip.instance.*.public_ip[0] : aws_instance.instance.public_ip |---------------- | aws_eip.instance is empty tuple The given key does not identify an element in this collection value.Error: Invalid index on .terraform/modules/server/modules/single-server/outputs.tf line 10, in output "public_ip": 10: value = var.attach_eip ? aws_eip.instance.*.public_ip[0] : aws_instance.instance.public_ip |---------------- | aws_eip.instance is empty tuple The given key does not identify an element in this collection value. ``` Changing the `attach_eip` input has no effect. Is there anything I can do to destroy the resources in the state?
In some cases, you can avoid all code errors in `terraform` and trigger a `destroy` of all resources by creating a new `empty` module: - Create a new module called `empty` with a single `main.tf` file that is empty. - Ensure the `empty` module points to the state file of the module you are trying to destroy - If you are using `terragrunt`, update the `terraform.source` attribute in `terragrunt.hcl` to point to the empty module. - If you are using `terraform`, update the `empty` module to have a `terraform.backend` config that points to the state file of your original module. - Now run `terragrunt init && terragrunt plan` (or `terraform init && terraform plan`). If you don't have nested providers (`provider` blocks nested in a terraform `module` call), this should create a valid plan to destroy all the resources. You can now run `terragrunt apply` or `terragrunt destroy` to destroy all the associated resources.