How to fix Error: Resource creation cancelled in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 31, 2025· 99 views

Resource creation cancelled occurs when Terraform interrupts or cancels the provisioning of a resource, either due to a dependent resource failure, user interruption, or context deadline. The state file may be left inconsistent with actual cloud resources.

Quick fix

Fixes Error: Resource creation cancelled

terraform apply 2>&1 | tee apply.log
  1. Scroll up and identify the root cause error
  2. Check your Terraform state file for inconsistencies
  3. Use terraform import to bring orphaned resources into state
  4. Check resource dependencies and use explicit depends_on
terraform — error
terraform apply 2>&1 | tee apply.log
Error: Resource creation cancelled

What this error means

This error indicates that Terraform initiated the cancellation of a resource creation operation. Unlike a hard failure from the cloud provider, cancellation happens when Terraform itself decides to stop the operation—typically because a prerequisite resource failed, the user pressed Ctrl+C, a deadline was reached, or a context was cancelled. This often leaves the infrastructure in an incomplete state where some resources exist in the cloud but Terraform's state file doesn't reflect them.

Typical symptoms

  • Terraform apply stops with 'Resource creation cancelled' for one or more resources
  • Other resources in the same apply complete successfully while dependent resources show cancelled
  • Scrolling up in the output shows a different error that appears to trigger the cascade of cancellations
  • State file is inconsistent with actual cloud resources (some exist but Terraform unaware)
  • Running terraform apply again produces different results on retry
  • Ctrl+C during apply results in partially completed infrastructure

Common causes

  1. A prerequisite or dependent resource failed to create, causing Terraform to cancel downstream resources
  2. User interrupted the apply operation by pressing Ctrl+C before completion
  3. Context deadline was exceeded on a parent resource, causing child resources to be cancelled
  4. Provider plugin crashed or was forcibly terminated mid-provisioning
  5. A precondition or lifecycle rule prevented the resource from being created
  6. Network connectivity was lost during apply, causing provider communication to drop

How to fix "Error: Resource creation cancelled"

1Scroll up and identify the root cause error

The 'Resource creation cancelled' message is usually a cascade effect. Look at the full Terraform output to find the original error that triggered the cancellation:

bash
terraform apply 2>&1 | tee apply.log

Search the log for the first error before any cancelled messages. The root cause could be:
- A network timeout
- Invalid resource configuration
- Missing required arguments
- Provider authentication failure

2Check your Terraform state file for inconsistencies

After interruption or cancellation, your state may be out of sync with the cloud:

bash
# Refresh state to see what actually exists
terraform refresh

# Check what Terraform thinks exists
terraform state list

# View the state for a specific resource
terraform state show aws_instance.example

If resources exist in the cloud but not in your state, you'll need to import them.

3Use terraform import to bring orphaned resources into state

If a resource was created in the cloud but Terraform's state wasn't updated due to cancellation:

bash
# Find the resource ID in your cloud provider console
# For AWS EC2:
terraform import aws_instance.example i-1234567890abcdef0

# For AWS RDS:
terraform import aws_db_instance.example mydb

# For Azure:
terraform import azurerm_resource_group.example /subscriptions/{subId}/resourceGroups/mygroup

After importing, run terraform plan to confirm no unintended changes.

4Check resource dependencies and use explicit depends_on

If cancellation is cascading through dependent resources, review your resource dependencies:

hcl
resource "aws_instance" "app_server" {
  # Ensure security group exists first
  vpc_security_group_ids = [aws_security_group.main.id]

  # Or use explicit dependency
  depends_on = [aws_security_group.main]
}

Use terraform graph to visualize dependencies:

bash
terraform graph | dot -Tsvg > graph.svg
5Retry with reduced parallelism to isolate issues

Run Terraform with reduced parallelism to create resources sequentially. This makes it easier to see which specific resource fails:

bash
# Create resources one at a time instead of in parallel (default is 10)
terraform apply -parallelism=1

This approach also prevents cascading cancellations—if one resource fails, only that one is affected, not a batch of dependent resources.

6Enable debug logging for detailed cancellation information

Get detailed traces of where and why cancellation occurred:

bash
export TF_LOG=trace
terraform apply 2>&1 | tee terraform-debug.log

# Search for cancellation context
grep -i 'cancel\|deadline\|context' terraform-debug.log

Look for messages like "context cancelled," "context deadline exceeded," or "run context exists, stopping." These indicate the exact point where Terraform initiated the cancellation.

7Verify cloud provider status and authentication

Ensure you have valid credentials and the cloud provider is accessible:

bash
# Test AWS credentials
aws sts get-caller-identity

# Test Azure login
az account show

# Test GCP credentials
gcloud auth list

Also check the cloud provider's status page for any service degradation or outages that might cause cancellations.

Advanced notes

Resource creation cancellation is particularly problematic because it can leave infrastructure in an inconsistent state. Terraform's interrupt handling has improved over versions, but if you're running terraform apply in an automated environment (CI/CD) that sends SIGTERM signals to all processes, Terraform may be killed mid-provision, causing the provider plugin to die abruptly and leaving resources partially created.

When cancellation happens during apply, Terraform attempts to gracefully shut down, but the state file may not be updated to reflect what was actually created in the cloud. This is why terraform import and terraform refresh are critical recovery steps.

For production deployments, consider: (1) using lifecycle prevent_destroy on critical resources, (2) splitting large deployments into smaller modules, (3) configuring appropriate timeouts, and (4) implementing proper monitoring and alerting for incomplete state.

Frequently asked questions

What does "Error: Resource creation cancelled" mean?
This error indicates that Terraform initiated the cancellation of a resource creation operation. Unlike a hard failure from the cloud provider, cancellation happens when Terraform itself decides to stop the operation—typically because a prerequisite resource failed, the user pressed Ctrl+C, a deadline was reached, or a context was cancelled. This often leaves the infrastructure in an incomplete state where some resources exist in the cloud but Terraform's state file doesn't reflect them.
How do I fix "Error: Resource creation cancelled"?
Resource creation cancelled occurs when Terraform interrupts or cancels the provisioning of a resource, either due to a dependent resource failure, user interruption, or context deadline. The state file may be left inconsistent with actual cloud resources.
What causes "Error: Resource creation cancelled"?
A prerequisite or dependent resource failed to create, causing Terraform to cancel downstream resources User interrupted the apply operation by pressing Ctrl+C before completion Context deadline was exceeded on a parent resource, causing child resources to be cancelled
Is the "Error: Resource creation cancelled" 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