Terraform apply hangs indefinitely on AWS VPC deletion
Problem
terraform apply hangs forever when trying to destroy an AWS VPC that has dependent resources (security groups, subnets, internet gateways) not managed by the current Terraform state. The AWS API never returns an error — it just waits. The operation must be killed manually. The fix requires identifying and deleting the unmanaged dependent resources first.
Error Output
aws_vpc.main: Still destroying... [id=vpc-0abc1234, 10m elapsed] aws_vpc.main: Still destroying... [id=vpc-0abc1234, 20m elapsed]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Delete unmanaged dependent resources before terraform destroy
AWS requires all dependent resources in a VPC (security groups, ENIs, subnets, IGW) to be deleted before the VPC can be deleted. Resources created outside Terraform are not tracked in state and block deletion indefinitely.
Trust Score
6 verifications
- 1
Kill the hanging terraform apply
Press Ctrl+C to cancel. Note the VPC ID from the error output.
- 2
Find all resources in the VPC
List all ENIs, security groups, and subnets in the VPC:
bashaws ec2 describe-network-interfaces --filters "Name=vpc-id,Values=vpc-XXXX" --query 'NetworkInterfaces[*].NetworkInterfaceId' aws ec2 describe-security-groups --filters "Name=vpc-id,Values=vpc-XXXX" --query 'SecurityGroups[?GroupName!=`default`].GroupId' - 3
Delete the unmanaged resources
Delete each resource that Terraform does not manage. Then re-run terraform destroy.
Validation
terraform destroy completes without hanging. VPC is deleted.
Verification Summary
Sign in to verify this fix
Environment
- Product
- Terraform + AWS
- Version
- 5.x
- Environment
- cloud
Submitted by
Alex Chen
2450 rep