How to fix Operation failed: Killed in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025· 194 views

The Terraform operation was terminated by the system, usually due to memory exhaustion or timeout. This occurs when the process consumes more resources than available, commonly with large state files or high-concurrency operations.

Quick fix

Fixes Operation failed: Killed

# On Linux, check dmesg for OOM killer events
sudo dmesg | grep -i 'out of memory\|killed process' | tail -20

# Check system memory usage during operation
free -h  # View total/available memory
vmstat 1 10  # Monitor memory in real-time
  1. Check system logs for OOM events
  2. Reduce parallelism to lower memory usage
  3. Increase available system memory
  4. Split large configurations into smaller modules
terraform — error
# On Linux, check dmesg for OOM killer events
sudo dmesg | grep -i 'out of memory\|killed process' | tail -20
# Check system memory usage during operation
free -h # View total/available memory
vmstat 1 10 # Monitor memory in real-time
Operation failed: Killed

What this error means

The 'Operation failed: Killed' error indicates that the Terraform process was forcibly terminated by the operating system or execution environment. This typically happens when the process exceeds available system memory (Out of Memory/OOM kill), reaches a timeout threshold in CI/CD pipelines, or is manually terminated. The error appears at the end of Terraform output when the entire process is terminated mid-execution rather than exiting cleanly.

Typical symptoms

  • Terraform plan or apply commands terminate abruptly with no error details
  • CI/CD pipeline shows 'Killed' message without standard Terraform error output
  • Operations fail intermittently when managing large numbers of resources
  • Error occurs after several minutes of successful progress during plan/apply
  • Works fine locally but fails consistently in CI/CD runners with resource constraints
  • dmesg logs show 'Out of memory: Kill process' on the machine

Common causes

  1. Out of Memory (OOM): The Terraform process exceeded available system RAM, especially common with large state files or many resources
  2. High parallelism: Default parallelism setting (10-15) with large configurations consumes excessive memory
  3. Large state files: Managing hundreds or thousands of resources creates large state JSON that consumes significant memory during operations
  4. CI/CD container limits: CI/CD runners (GitHub Actions, GitLab CI, Jenkins agents) often have tight memory constraints
  5. Insufficient system resources: The hosting machine has insufficient CPU, RAM, or disk I/O for the workload
  6. Process timeout: Execution environment forcibly terminates long-running Terraform operations that exceed time limits
  7. Memory leaks: Provider plugins or custom providers may have memory leaks during long operations

How to fix "Operation failed: Killed"

1Check system logs for OOM events

First, verify if the process was killed due to memory exhaustion:

bash
# On Linux, check dmesg for OOM killer events
sudo dmesg | grep -i 'out of memory\|killed process' | tail -20

# Check system memory usage during operation
free -h  # View total/available memory
vmstat 1 10  # Monitor memory in real-time

If you see 'killed process' messages, memory exhaustion is the cause. Proceed to step 2.

2Reduce parallelism to lower memory usage

By default, Terraform executes 10 parallel operations. Reducing this value lowers peak memory consumption:

bash
# Apply with reduced parallelism (use 2-3 for constrained environments)
terraform plan -parallelism=3
terraform apply -parallelism=3

# Set globally in .terraformrc for persistent effect
echo 'apply {
  parallelism = 3
}' >> ~/.terraformrc

Start with -parallelism=3 and increase if the operation completes successfully. Lower values are safer but slower.

3Increase available system memory

If running in CI/CD or cloud environments, increase allocated resources:

GitHub Actions:

yaml
jobs:
  terraform:
    runs-on: ubuntu-latest  # Consider ubuntu-latest for more resources
    # GitHub Actions provides ~7GB RAM for ubuntu-latest

Docker/Container:

bash
# Allocate more memory to container
docker run --memory=4g my-terraform-image

Cloud VMs (AWS/Azure/GCP):
- Upgrade instance type to one with more RAM
- Consider memory-optimized instance families

Local development:

bash
# Monitor and ensure sufficient free memory
free -h
df -h  # Check disk space too
4Split large configurations into smaller modules

Breaking infrastructure into separate state files/workspaces reduces per-operation memory demand:

Recommended structure:

bash
terraform/
  ├── networking/     # VPCs, subnets, security groups
  │   └── main.tf
  ├── compute/        # EC2, containers, compute resources
  │   └── main.tf
  ├── databases/      # RDS, DynamoDB, storage
  │   └── main.tf
  └── monitoring/     # CloudWatch, logs, alerts
      └── main.tf

Benefits:
- Each module runs independently with smaller state file
- Faster plans and applies
- Easier to parallelize and debug
- Lower memory per operation

Run each independently:

bash
cd terraform/networking && terraform apply
cd ../compute && terraform apply
cd ../databases && terraform apply
5Use terraform apply -target for specific resources (temporary fix)

If full apply fails but must proceed, target specific resource groups:

bash
# Apply only compute resources
terraform apply -target='module.compute' -parallelism=2

# Apply specific resources
terraform apply -target='aws_instance.web' -target='aws_instance.app'

# Combine with state file backup
terraform state pull > backup.tfstate
terraform apply -target='module.database' -parallelism=2

Caution: -target is a debugging tool. Use it temporarily to recover from failures, but plan to refactor your configuration long-term (see step 4).

6Upgrade Terraform and provider versions

Memory efficiency improves in newer versions. Update to latest stable releases:

bash
# Check current version
terraform version

# Upgrade Terraform (macOS with Homebrew)
brew upgrade terraform

# Upgrade Terraform (manually)
# Download from https://www.terraform.io/downloads

# Upgrade providers in your configuration
required_providers {
  aws = {
    source  = "hashicorp/aws"
    version = "~> 5.0"  # Latest major version
  }
}

# Run init to update providers
terraform init -upgrade

Newer versions often include memory optimizations and bug fixes for large configurations.

7For CI/CD timeouts, increase job timeout settings

If 'Killed' occurs due to timeout rather than memory:

GitHub Actions:

yaml
jobs:
  terraform:
    timeout-minutes: 60  # Default is 360 (6 hours)
    runs-on: ubuntu-latest

GitLab CI:

yaml
terraform_apply:
  timeout: 2h  # Default is 1h
  script:
    - terraform apply -auto-approve

Jenkins:

groovy
timeout(time: 2, unit: 'HOURS') {
  sh 'terraform apply -auto-approve'
}

Also set TFE_PARALLELISM environment variable if using Terraform Cloud/Enterprise:

bash
export TFE_PARALLELISM=3
terraform plan

Advanced notes

For Terraform Enterprise/Cloud users: If running remote operations in TFE, memory is constrained per workspace. Contact HashiCorp support to increase the worker instance class or enable Agent-based runs which use your own compute. The Terraform Enterprise troubleshooting guide recommends checking system dmesg logs via SSH to the node and increasing the maximum memory allocation.

Linux-specific considerations: Check SELinux and cgroup memory limits, which may artificially constrain available memory:

bash
grep MemLimit /proc/cgroups
cat /proc/self/cgroup | grep memory

Provider-specific issues: Some providers (e.g., AWS provider v6.0.0) had memory-leak issues in specific versions. Always check provider changelogs and upgrade to patch releases.

For rootless Docker or constrained environments: Consider using -refresh=false to skip state refresh (speeds up operations and uses less memory), but only if you're certain remote state matches:

bash
terraform apply -refresh=false -parallelism=2

Frequently asked questions

What does "Operation failed: Killed" mean?
The 'Operation failed: Killed' error indicates that the Terraform process was forcibly terminated by the operating system or execution environment. This typically happens when the process exceeds available system memory (Out of Memory/OOM kill), reaches a timeout threshold in CI/CD pipelines, or is manually terminated. The error appears at the end of Terraform output when the entire process is terminated mid-execution rather than exiting cleanly.
How do I fix "Operation failed: Killed"?
The Terraform operation was terminated by the system, usually due to memory exhaustion or timeout. This occurs when the process consumes more resources than available, commonly with large state files or high-concurrency operations.
What causes "Operation failed: Killed"?
Out of Memory (OOM): The Terraform process exceeded available system RAM, especially common with large state files or many resources High parallelism: Default parallelism setting (10-15) with large configurations consumes excessive memory Large state files: Managing hundreds or thousands of resources creates large state JSON that consumes significant memory during operations
Is the "Operation failed: Killed" 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