Terraform: Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deleted
Destroy failed because something else still uses the resource (ENIs, subnets, gateways, security group rules).
Error: deleting EC2 VPC (vpc-0abc): DependencyViolation: The vpc 'vpc-0abc' has dependencies and cannot be deletedDependencyViolation: resource sg-0abc has a dependent objectError: deleting Security Group: DependencyViolationError: error deleting subnet: DependencyViolation: The subnet has dependencies and cannot be deletedError deleting: DependencyViolation Meaning
Find what's attached (network interfaces, load balancers, endpoints, Lambda ENIs, resources created outside Terraform). Remove/detach them first, or fix dependency ordering with depends_on. Lambda/EKS leave ENIs that take minutes to release — retry. Use console/CLI (aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=...) to locate blockers.
Common causes
- ENIs from Lambda/EKS/ELB still attached
- Resources created manually in the VPC/subnet
- Security group referenced by another SG
- Missing dependency ordering
- Eventual consistency delay
⚡ Quick fix
- List dependents with the CLI and delete them
- Retry destroy after a few minutes
- Add explicit
depends_onor manage dependents in Terraform
Detailed fix by platform
AWS
aws ec2 describe-network-interfaces --filters Name=vpc-id,Values=vpc-0abc --query 'NetworkInterfaces[].[NetworkInterfaceId,Description]'
How to diagnose
- Dependents — Which?
- Origin — Managed by TF?
- Retry — After delay?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- BucketNotEmpty: bucket you tried to delete is not empty Terraform: Error: deleting S3 Bucket (my-bucket): BucketNotEmpty: The bucket you tried to delete is not empty
- Error: Cycle (dependency cycle) Terraform: Error: Cycle: aws_security_group.a, aws_security_group.b
- Instance cannot be destroyed (lifecycle.prevent_destroy) Terraform: Error: Instance cannot be destroyed — Resource aws_db_instance.prod has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed
Most viewed in Terraform
- Error acquiring the state lock Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked
- Inconsistent dependency lock file Terraform: Error: Inconsistent dependency lock file — provider x: required by this configuration but no version is selected
- Reference to undeclared resource Terraform: Error: Reference to undeclared resource / Reference to undeclared input variable
Other ways to find it
Where this error sits
Origin: Platform & cloud. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026