InsufficientIPAddressesInSubnet
terraform
resource_error
ai_generated
true
Error: error creating EC2 Instance: insufficient IP addresses in subnet (subnet-abc123) when creating a new instance
ID: terraform/insufficient-ip-addresses-in-subnet
85%Fix Rate
86%Confidence
1Evidence
2024-01-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Terraform v1.5 | active | — | — | — |
| Terraform v1.6 | active | — | — | — |
| Terraform v1.7 | active | — | — | — |
| AWS Provider v5.0 | active | — | — | — |
Root Cause
The AWS subnet has exhausted its available IP addresses, often due to too many ENIs or instances consuming the CIDR range, or the subnet's CIDR block being too small.
generic中文
AWS 子网已耗尽可用 IP 地址,通常是由于过多的 ENI 或实例消耗了 CIDR 范围,或者子网的 CIDR 块太小。
Official Documentation
https://docs.aws.amazon.com/vpc/latest/userguide/subnet-sizing.htmlWorkarounds
-
95% success Increase the subnet CIDR block size: update `cidr_block = "10.0.1.0/24"` to a larger range like `10.0.1.0/23` (requires recreating the subnet) or add a new subnet with a larger CIDR.
Increase the subnet CIDR block size: update `cidr_block = "10.0.1.0/24"` to a larger range like `10.0.1.0/23` (requires recreating the subnet) or add a new subnet with a larger CIDR.
-
80% success Use `aws ec2 describe-subnets --subnet-ids subnet-abc123 --query 'Subnets[0].AvailableIpAddressCount'` to check available IPs, then reduce instance count or use a different subnet with free IPs.
Use `aws ec2 describe-subnets --subnet-ids subnet-abc123 --query 'Subnets[0].AvailableIpAddressCount'` to check available IPs, then reduce instance count or use a different subnet with free IPs.
-
70% success Implement a lifecycle policy to terminate idle instances or use auto-scaling with a minimum/maximum size to free IPs dynamically.
Implement a lifecycle policy to terminate idle instances or use auto-scaling with a minimum/maximum size to free IPs dynamically.
中文步骤
Increase the subnet CIDR block size: update `cidr_block = "10.0.1.0/24"` to a larger range like `10.0.1.0/23` (requires recreating the subnet) or add a new subnet with a larger CIDR.
Use `aws ec2 describe-subnets --subnet-ids subnet-abc123 --query 'Subnets[0].AvailableIpAddressCount'` to check available IPs, then reduce instance count or use a different subnet with free IPs.
Implement a lifecycle policy to terminate idle instances or use auto-scaling with a minimum/maximum size to free IPs dynamically.
Dead Ends
Common approaches that don't work:
-
Increasing the instance count in the Terraform configuration without adjusting the subnet CIDR
95% fail
More instances will consume more IPs, worsening the shortage; Terraform will fail with the same error for each new instance.
-
Deleting unused instances manually via AWS console but not updating Terraform state
70% fail
Terraform state still tracks deleted instances, causing drift; subsequent apply may try to recreate them, consuming IPs again.
-
Changing the subnet ID to a different existing subnet without verifying its IP availability
60% fail
The new subnet may also have limited IPs; without checking available addresses, the error may simply move to another subnet.