Terraform timed out waiting for a resource to reach its desired state during creation. This typically happens when cloud API operations take longer than expected, network connectivity is interrupted, or resource dependencies aren't properly configured.
This error occurs when Terraform initiates a resource creation request to a cloud provider (AWS, GCP, Azure, etc.) but doesn't receive confirmation that the resource reached its desired state within the specified timeout period. The timeout can be triggered by slow API responses, network latency, insufficient provider quotas, or the resource still being in an intermediate state when Terraform stops waiting. Terraform's default timeouts vary by resource type and cloud provider, typically ranging from 15 minutes to 120 minutes.
Even if Terraform times out, the resource may have been successfully created in the cloud provider. Check your cloud console:
AWS:
aws ec2 describe-instances --region us-east-1GCP:
gcloud compute instances list --project=your-projectAzure:
az resource list --resource-group your-rgIf the resource exists, you can import it into Terraform state using terraform import.
Add or modify the timeouts block in your resource configuration to allow more time:
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
timeouts {
create = "30m"
delete = "10m"
}
}
resource "google_compute_instance" "example" {
name = "my-instance"
machine_type = "n1-standard-1"
timeouts {
create = "20m"
delete = "15m"
}
}Check the Terraform provider documentation for the specific resource to see which timeout attributes are supported (create, update, delete).
Ensure your network allows outbound connections to the cloud provider APIs:
# Test connectivity to AWS API
curl -I https://ec2.amazonaws.com/
# Test connectivity to GCP API
curl -I https://www.googleapis.com/
# Test connectivity to Azure API
curl -I https://management.azure.com/If you're behind a corporate firewall, proxy, or VPN, ensure those are properly configured. Check with your network administrator if API calls are being blocked or throttled.
Complex resources with many attributes, user data scripts, or dependencies take longer to initialize:
# Before - complex with user data
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.xlarge"
user_data = file("${path.module}/init-script.sh") # Long-running script
root_block_device {
volume_size = 100
volume_type = "gp3"
}
network_interface {
device_index = 0
security_groups = [aws_security_group.web.id]
subnet_id = aws_subnet.private.id
}
}
# After - minimal, add complexity later
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
# Add complex configuration after initial creation
}Start with minimal configuration and add attributes after the resource is created.
Resource creation may fail silently or stall if you've hit account quotas:
AWS:
# Check EC2 capacity
aws ec2 describe-account-attributes --attribute-names supported-platforms
# Check service quotas
aws service-quotas list-service-quotas --service-code ec2GCP:
# View quotas in Cloud Console
# Go to: APIs & Services > Quotas
# Or via gcloud
gcloud compute project-info describe --project=your-projectAzure:
az vm list-usage --location eastusIf quotas are exceeded, request a quota increase from the cloud provider.
If your resource has a user data script or initialization command, it may be hanging:
# Check user data script for infinite loops
resource "aws_instance" "example" {
user_data = "#!/bin/bash\nset -e\necho 'Starting...'; apt-get update -y; echo 'Done';"
}
# Use time_sleep to add delays between resource creation
resource "time_sleep" "wait_30_seconds" {
create_duration = "30s"
}
resource "aws_instance" "after_wait" {
depends_on = [time_sleep.wait_30_seconds]
# ... rest of config
}You can also SSH into the instance (if it was created) and check logs:
ssh -i /path/to/key.pem ec2-user@instance-ip
tail -f /var/log/cloud-init-output.logIf the resource exists in the cloud provider but Terraform timed out, import it into your state:
# First, remove the resource from your .tf files that's causing timeout
# Then create an empty resource block:
resource "aws_instance" "example" {}
# Import the existing resource
terraform import aws_instance.example i-1234567890abcdef0
# Add configuration to match the actual resource
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
# ... other attributes
}
# Verify the import
terraform planProvider-Specific Timeout Defaults: AWS resources often have generous defaults (up to 120 minutes for complex resources), while GCP and Azure may use shorter defaults. Always check the Terraform Registry documentation for each provider. Context Deadline Exceeded: When timeouts are exceeded, the SDK returns 'context: deadline exceeded' error—this indicates the timeout mechanism itself fired, not necessarily that the API is completely broken. The API may still be processing the request on the server side. Idempotency: Terraform's create timeout failure doesn't necessarily mean the resource creation was rolled back. For safe recovery, verify in the cloud console whether the resource was created, then use terraform import to sync state. For CI/CD pipelines, consider using exponential backoff retries or increasing timeouts for environments known to have latency. Some providers support partial creation states—you can resume from where Terraform stopped by adjusting timeout and retrying.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform