This error occurs when AWS lacks sufficient On-Demand capacity to provision your requested EC2 instance type in the chosen Availability Zone. Capacity constraints are usually temporary and can be resolved by trying different AZs, instance types, or retrying after a few minutes.
The InsufficientInstanceCapacity error indicates that AWS does not currently have enough available On-Demand resources to fulfill your request for a specific instance type in your requested Availability Zone. This is a temporary capacity constraint that AWS experiences during periods of high demand. The error is not due to misconfiguration or insufficient permissions—rather, it reflects real-time resource availability in AWS infrastructure.
AWS capacity is highly dynamic and changes frequently. Wait 2-5 minutes and re-run terraform apply. The capacity issue may resolve as AWS provisions additional resources.
terraform applyInstead of specifying a hardcoded Availability Zone, let AWS select from available capacity across all AZs in the region. Remove or comment out the availability_zone parameter.
Before:
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m5.large"
availability_zone = "us-east-1a"
}After:
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m5.large"
# availability_zone removed - AWS will choose from available capacity
}If you must specify an AZ, try different ones. Capacity varies by AZ, and another AZ in the same region may have capacity available.
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m5.large"
availability_zone = "us-east-1b" # Changed from us-east-1a
}Or use multiple AZs with Auto Scaling Groups for automatic failover:
resource "aws_autoscaling_group" "example" {
availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"]
# AWS will launch in any AZ with available capacity
}If your specific instance type is unavailable, switch to an alternative in the same family with similar specifications. For example, if m5.large is unavailable, try m5.xlarge, m6i.large, or t3.large.
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m6i.large" # Changed from m5.large
}If deploying multiple instances, split them into smaller groups. This distributes the load and improves the chance of successful provisioning.
Before:
resource "aws_instance" "fleet" {
count = 10
ami = "ami-12345678"
instance_type = "m5.large"
}After:
resource "aws_instance" "fleet" {
count = 3 # Reduced from 10
ami = "ami-12345678"
instance_type = "m5.large"
}
# Run terraform apply multiple times or in batchesIf this is production-critical, reserve EC2 capacity in advance using Capacity Reservations. This guarantees availability but incurs charges whether the capacity is used or not.
resource "aws_ec2_capacity_reservation" "example" {
instance_type = "m5.large"
instance_platform = "Linux/UNIX"
availability_zone = "us-east-1a"
instance_count = 5
}
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m5.large"
capacity_reservation_id = aws_ec2_capacity_reservation.example.id
}Spot Instances are much cheaper and have greater availability. Use them for non-critical or temporary workloads.
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "m5.large"
instance_interruption_behavior = "stop"
spot_price = "0.05" # Set a bid price
}AWS capacity constraints are a natural part of cloud infrastructure management. The capacity available in any region or AZ fluctuates based on overall AWS customer demand and infrastructure maintenance. High-demand instance types (GPU, high-memory, or specialized types like g5.12xlarge) are more prone to capacity issues. For production workloads, use Capacity Reservations or Reserved Instances to guarantee availability, though this incurs charges whether capacity is used. The Terraform AWS provider will retry failed instance launches with exponential backoff, which can result in extended deployment times (up to 50 minutes) before ultimately failing. Setting wait_for_capacity_timeout in certain resources can help control this behavior. For Auto Scaling Groups, AWS recommends specifying multiple instance types and AZs to improve provisioning success rates.
Error: Error rendering template: template not found
How to fix "template not found" error in Terraform
Error: Error generating private key
How to fix 'Error generating private key' in Terraform
Error creating Kubernetes Service: field is immutable
How to fix "field is immutable" errors in Terraform
Error: Error creating local file: open: permission denied
How to fix "Error creating local file: permission denied" in Terraform
Error: line endings have changed from CRLF to LF
Line endings have changed from CRLF to LF in Terraform