terraform-aws-modules / terraform-aws-vpc

Terraform module to create AWS VPC resources πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws
Apache License 2.0
2.92k stars 4.36k forks source link

deleting EC2 Subnet (subnet-xxxxxxx): DependencyViolation: The subnet 'subnet-xxxxxxx' has dependencies and cannot be deleted. #1081

Open GanesanChandran opened 1 month ago

GanesanChandran commented 1 month ago

Description

I have used terraform VPC module to create the VPC through Terragrunt. When i try to delete the VPC, it got hanged and throw EC2 Subnet (subnet-xxxxx): DependencyViolation error.

Versions

Module version [Required]:

Terragrunt version: v0.55.20

Provider version(s): registry.terraform.io/hashicorp/aws v5.42.0

Reproduction Code [Required]

  source = "terraform-aws-modules/vpc/aws"
  version = **"4.0.0"**
  name   = local.vpc_name
  cidr   = var.vpc_cidr

  azs              = var.availability_zones
  public_subnets   = var.public_subnets
  private_subnets  = var.private_subnets
  database_subnets = var.database_subnets

  create_database_subnet_group = true
  manage_default_route_table   = true
  default_route_table_tags     = { DefaultRouteTable = true }

  enable_dns_hostnames = true
  enable_dns_support   = true

  enable_nat_gateway     = true
  one_nat_gateway_per_az = true

  enable_vpn_gateway = false
  map_public_ip_on_launch = false

  manage_default_security_group  = true
  default_security_group_ingress = []
  default_security_group_egress  = []

  enable_flow_log                                 = true
  create_flow_log_cloudwatch_log_group            = true
  create_flow_log_cloudwatch_iam_role             = true
  flow_log_max_aggregation_interval               = 60
  flow_log_cloudwatch_log_group_retention_in_days = 30

  tags = var.default-tags
}

When i apply destroy command to delete the vpc, i got below.

module.vpc.aws_subnet.private[1]: Destroying... [id=subnet-xxxxx]
module.vpc.aws_subnet.private[0]: Destroying... [id=subnet-xxxxx]

Error: deleting EC2 Subnet (subnet-xxxxx): DependencyViolation: The subnet 'subnet-xxxxx' has dependencies and cannot be deleted.
β”‚   status code: 400, request id: 76947801-c590-4a79-bfdb-6468693133b8
β”‚ 
β”‚ 

β”‚ Error: deleting EC2 Subnet (subnet-xxxxx): DependencyViolation: The subnet 'subnet-xxxxx' has dependencies and cannot be deleted.
β”‚   status code: 400, request id: eaffa1e1-870d-43e3-a32a-434fffcd75ad

It got hanged in deleting the subnet. Above two subnets are private subnets.

Expected behavior

The plan is applied, deleting the VPC and associated subnets.

Actual behavior

It will say "Still destroying" for about 20 minutes, before it gives up saying the subnet has dependencies: module.vpc.aws_subnet.private[2]: Destroying... [id=subnet-xxxxxx] module.vpc.aws_subnet.private[1]: Still destroying... [id=subnet-xxxxx, 19m20s elapsed] ... Error: deleting EC2 Subnet (subnet-xxxxx): DependencyViolation: The subnet 'subnet-xxxxx' has dependencies and cannot be deleted. β”‚ status code: 400, request id: 76947801-c590-4a79-bfdb-6468693133b8

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

GanesanChandran commented 4 days ago

Any update on this?