How to fix Error creating NAT Gateway: NatGatewayLimitExceeded in Terraform
You've reached the AWS NAT gateway quota (default 5 per Availability Zone). This occurs when provisioning infrastructure with Terraform and your account has too many NAT gateways in the same AZ or Deleting status gateways haven't fully cleaned up yet.
Quick fix
Fixes Error creating NAT Gateway: NatGatewayLimitExceeded
aws ec2 describe-nat-gateways --region us-east-1 \
--query 'NatGateways[*].[NatGatewayId,State,SubnetId]' \
--output table- Check existing NAT gateway count and status
- Wait for Deleting NAT gateways to fully delete
- Delete unused NAT gateways if safe
- Optimize Terraform configuration to use fewer NAT gateways
aws ec2 describe-nat-gateways --region us-east-1 \--query 'NatGateways[*].[NatGatewayId,State,SubnetId]' \--output tableError creating NAT Gateway: NatGatewayLimitExceeded
What this error means
AWS enforces a quota on the number of NAT gateways you can create in each Availability Zone. The default limit is 5 NAT gateways per AZ. This prevents resource exhaustion and helps manage costs. A NAT gateway in Pending, Available, or Deleting state counts against this limit. When Terraform tries to create a NAT gateway and this quota is exceeded, AWS rejects the operation with the NatGatewayLimitExceeded error.
Typical symptoms
- Terraform apply fails with 'NatGatewayLimitExceeded' error
- Unable to create VPC infrastructure with multiple NAT gateways
- Error occurs even after attempting to destroy previous NAT gateways
- Happens when scaling infrastructure across multiple availability zones
Common causes
- You have already created 5 NAT gateways in the target Availability Zone
- Recently deleted NAT gateways are still in Deleting state and count against the quota
- Terraform modules create one NAT gateway per subnet instead of per availability zone
- Different accounts or environments share the same AWS account and have multiple NAT gateways deployed
- Regional NAT gateways are enabled and consuming quota in multiple AZs
How to fix "Error creating NAT Gateway: NatGatewayLimitExceeded"
Log into the AWS Console and navigate to the VPC service. Click on NAT gateways to see all gateways in your region. Count how many exist in each Availability Zone and note which ones are in Deleting status. This tells you how much quota you're consuming.
Alternatively, use the AWS CLI:
aws ec2 describe-nat-gateways --region us-east-1 \
--query 'NatGateways[*].[NatGatewayId,State,SubnetId]' \
--output tableIf you see NAT gateways in Deleting state, these still count against your quota. Wait 2-5 minutes for them to transition to Deleted state, then they won't consume quota. Verify completion with:
aws ec2 describe-nat-gateways --region us-east-1 \
--filter "Name=state,Values=deleted" \
--query 'NatGateways[*].NatGatewayId'If you have NAT gateways that are no longer needed, delete them to free up quota. First verify nothing depends on them by checking route tables:
aws ec2 describe-route-tables --region us-east-1 \
--query "RouteTables[?Routes[?NatGatewayId=='nat-12345678']].RouteTableId"Then delete via the console or CLI:
aws ec2 delete-nat-gateway --nat-gateway-id nat-12345678 --region us-east-1Review your Terraform code to ensure you're not creating more NAT gateways than necessary. Use module options to limit creation:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
# Option 1: Single NAT gateway for entire VPC (cost-effective but less resilient)
single_nat_gateway = true
# Option 2: One NAT gateway per availability zone (recommended)
one_nat_gateway_per_az = true
# Avoid: Creating one NAT gateway per private subnet
# This consumes quota quickly and is unnecessary
}If you legitimately need more than 5 NAT gateways per AZ:
1. Go to the AWS Service Quotas console: https://console.aws.amazon.com/servicequotas
2. Search for "NAT gateways per Availability Zone"
3. Click on the quota and select "Request quota increase"
4. Enter the desired value (AWS typically approves reasonable increases)
5. Submit the request and wait for approval
Alternatively, use the CLI:
aws service-quotas request-service-quota-increase \
--service-code vpc \
--quota-code L-FE5A380F \
--desired-value 10 \
--region us-east-1Once you've freed up quota or received approval for an increase, retry your Terraform deployment:
terraform plan
terraform applyIf using destroy and recreate, wait for all resources to fully delete before reapplying:
terraform destroy
# Wait 2-5 minutes
terraform applyAdvanced notes
NAT gateway limits are per Availability Zone, not per region or account. You can have 5 in us-east-1a, 5 in us-east-1b, and 5 in us-east-1c simultaneously. Regional NAT gateways (in preview) may have different quota behavior - check AWS documentation if you're using them. If you have cross-account infrastructure, ensure NAT gateways are distributed across accounts to avoid hitting a single account's quota. For very high availability needs with multiple NAT gateways, consider using Gateway Load Balancer instead of managing many separate NAT gateways.
Frequently asked questions
- What does "Error creating NAT Gateway: NatGatewayLimitExceeded" mean?
- AWS enforces a quota on the number of NAT gateways you can create in each Availability Zone. The default limit is 5 NAT gateways per AZ. This prevents resource exhaustion and helps manage costs.
- How do I fix "Error creating NAT Gateway: NatGatewayLimitExceeded"?
- You've reached the AWS NAT gateway quota (default 5 per Availability Zone). This occurs when provisioning infrastructure with Terraform and your account has too many NAT gateways in the same AZ or Deleting status gateways haven't fully cleaned up yet.
- What causes "Error creating NAT Gateway: NatGatewayLimitExceeded"?
- You have already created 5 NAT gateways in the target Availability Zone Recently deleted NAT gateways are still in Deleting state and count against the quota Terraform modules create one NAT gateway per subnet instead of per availability zone
- Is the "Error creating NAT Gateway: NatGatewayLimitExceeded" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Terraform Official Documentation
- ๐
- ๐
- ๐
- ๐