'Terraform keeps destroying internet gateway forever
I have a set of .tf files that reflect an AWS infra.
The files in my terraform folder are more or less:
eip.tf
instance.tf
key.tf
provider.tf
rds.tf
route53.tf
securitygroup.tf
terraform.tfstate
terraform.tfstate.1520442018.backup
terraform.tfstate.backup
terraform.tfvars
terraform.tfvars.dist
vars.tf
vpc.tf
I created the infra and I want to destroy it.
I see that the internet gateway destruction takes forever:
aws_internet_gateway.my-gw: Still destroying... (ID: igw-d53fa0b2, 14m50s elapsed)
By browsing in my aws console I see that this is because my ec2 instance is still up and running.
Why is terraform trying to destroy the internet gateway without making sure the ec2 instance is down?
How can I prevent this from hapenning again?
The same scripts have executed (apply/destroy) many times before without any issues.
Solution 1:[1]
Turns out this was due to my instance having been created with this:
# enable termination protection
disable_api_termination = true
This will apparently prevent normal termination behavior from terraform.
Solution 2:[2]
Had the same issue but mine was because I had deletion protection turned on for a Load Balancer
enable_deletion_protection = true
I just logged into AWS and manually disabled by editing the Load Balancer.
I suppose you could terraform apply the change and then terraform destroy everything but if you're seeing this error you've most likely destroyed most of your infrastructure already and you don't want to re-create it all just to allow you to destroy it all again.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pkaramol |
| Solution 2 | Joel B |

