Closed dan-hook closed 1 year ago
I believe this occurs because terraform tries to delete the subnet before it runs this modification on the vpc_endpoint:
Correct. Its the order of operations that cause a chicken vs the egg type scenario:
Since the VPC endpoints module relies on the subnet IDs output from the VPC module, Terraform starts with the VPC module and attempts to remove the subnet. This subnet cannot be removed due to the fact that a endpoint is provisioned there
I'm going to lock this issue because it has been closed for 30 days β³. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Description
Deploying a VPC with an endpoint with 3 AZs, then reducing the number to 2 AZs fails.
Versions
Module version [Required]:
Terraform version: 1.6.1
Provider version(s): registry.terraform.io/hashicorp/aws v5.22.0
Reproduction Code [Required]
Steps to reproduce the behavior:
Deploy the module as above. Change the line: azs = slice(data.aws_availability_zones.available.names, 0, 3) to azs = slice(data.aws_availability_zones.available.names, 0, 2)
Plan the module. It will show that it's deleting and changing a number of resources. Apply the plan.
Expected behavior
The plan is applied, deleting the third subnet.
Actual behavior
It will say "Still destroying" for about 20 minutes, before it gives up saying the subnet has dependencies: terraform apply tfplan module.vpc.aws_route_table_association.private[2]: Destroying... [id=rtbassoc-051fbfbd50d9d8536] module.vpc.aws_route_table_association.private[2]: Destruction complete after 0s module.vpc.aws_subnet.private[2]: Destroying... [id=subnet-0710ac7c70335c514] module.vpc.aws_route_table.private[2]: Destroying... [id=rtb-09a5a0c0ac9ed26b2] module.vpc.aws_route_table.private[2]: Destruction complete after 1s module.vpc.aws_subnet.private[2]: Still destroying... [id=subnet-0710ac7c70335c514, 10s elapsed] ... Error: deleting EC2 Subnet (subnet-0710ac7c70335c514): DependencyViolation: The subnet 'subnet-0710ac7c70335c514' has dependencies and cannot be deleted. β status code: 400, request id: 648b69ac-01eb-4435-a95c-ee2652a156d2
Additional context
Trying to delete the subnet from the console will say "Subnets have network interfaces and cannot be deleted". This is because an ENI still exists. I believe this occurs because terraform tries to delete the subnet before it runs this modification on the vpc_endpoint: