How to fix No space left on device in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 30, 2025ยท 155 views

The "No Space Left on Device" error occurs when Terraform runs out of disk space during initialization, planning, or apply operations. This typically happens in CI/CD environments or when provider caches grow too large. Diagnose disk usage and implement caching strategies to resolve.

Quick fix

Fixes No space left on device

# Check disk usage
df -h

# Check inode usage (can be full even with space left)
df -i

# Find what's consuming space
du -sh ~/ /tmp/ /var/tmp/ 2>/dev/null
du -sh .terraform/
  1. Check available disk space
  2. Clear .terraform cache
  3. Configure provider caching to reduce disk usage
  4. For CI/CD: Clean up before each run
terraform โ€” error
# Check disk usage
df -h
# Check inode usage (can be full even with space left)
df -i
# Find what's consuming space
du -sh ~/ /tmp/ /var/tmp/ 2>/dev/null
du -sh .terraform/
No space left on device

What this error means

This error occurs when Terraform attempts to write files (provider plugins, state, or temporary files) but the filesystem has zero available space. Unlike some errors that may have misleading messages, this one is usually literal - the disk is genuinely full. The error can occur at various stages: - During "terraform init" when downloading and extracting provider plugins - During "terraform plan" when creating temporary files - During "terraform apply" when writing state files - In CI/CD when containers or build agents have limited storage

Typical symptoms

  • Error message: "No space left on device" during terraform init
  • terraform plan fails partway through
  • CI/CD pipeline suddenly fails but was working before
  • Provider plugin downloads fail and stop mid-extraction
  • Error occurs inconsistently (sometimes passes, sometimes fails)
  • Issues started appearing gradually over time
  • Local machine has space but CI environment runs out

Common causes

  1. CI/CD build agent disk is full from previous builds
  2. Provider cache (.terraform directory) grew too large across multiple workspaces
  3. Each workspace downloads separate copies of provider plugins
  4. Docker container or ephemeral build environment has limited disk
  5. Terraform state files accumulating in temporary directories
  6. Old provider versions not cleaned up in shared cache
  7. Root partition smaller than required for Terraform operations
  8. Multiple concurrent Terraform operations filling /tmp or TMPDIR

How to fix "No space left on device"

1Check available disk space

Identify the bottleneck:

bash
# Check disk usage
df -h

# Check inode usage (can be full even with space left)
df -i

# Find what's consuming space
du -sh ~/ /tmp/ /var/tmp/ 2>/dev/null
du -sh .terraform/

Look for filesystems at 100% capacity.

2Clear .terraform cache

Remove provider cache to free space:

bash
# In your Terraform working directory
rm -rf .terraform/

# Or just remove provider plugins
rm -rf .terraform/providers/

# For multiple workspaces
find . -name ".terraform" -type d -exec rm -rf {} +

You'll need to run terraform init again to re-download providers.

3Configure provider caching to reduce disk usage

Set up shared provider cache for all projects:

bash
# Create cache directory (use a location with more space)
mkdir -p ~/.terraform.d/plugin-cache

# Set environment variable
export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"

# Make persistent in ~/.bashrc or ~/.zshrc
echo 'export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/plugin-cache"' >> ~/.bashrc

Or configure in ~/.terraformrc:

hcl
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"

This shares provider binaries across all projects instead of duplicating them.

4For CI/CD: Clean up before each run

Add cleanup steps to your CI pipeline:

yaml
# GitHub Actions
- name: Clean Terraform cache
  run: |
    rm -rf ~/.terraform.d/plugin-cache
    rm -rf .terraform/
    df -h

- name: Terraform Init
  run: terraform init

# GitLab CI
script:
  - rm -rf ~/.terraform.d/plugin-cache .terraform/
  - df -h
  - terraform init
  - terraform plan

Run this before every terraform init to ensure a clean state.

5For CI/CD: Increase available disk space

Configure larger storage in your CI system:

yaml
# GitHub Actions - use larger runner
runs-on: ubuntu-latest-xl  # More disk than ubuntu-latest

# GitLab CI
resources:
  disk: 100Gi

# Docker - increase container disk
docker run --storage-opt size=100G

# Kubernetes - increase PVC
resources:
  requests:
    storage: 100Gi
6Set TMP/TMPDIR to directory with space

If /tmp is full, redirect to alternate location:

bash
# Check /tmp usage
du -sh /tmp

# Use location with more space
export TMPDIR="/path/with/more/space"
export TMP="$TMPDIR"

# Run terraform
terraform init
terraform plan

This prevents Terraform from filling /tmp during operations.

7Disable lock files if not needed

Reduce filesystem writes in minimal environments:

bash
# Disable lock file (only if not using state locking)
terraform init -lock=false

# Or in terraform config
terraform {
  backend "s3" {
    skip_credentials_validation = true
    skip_requesting_account_id  = true
    skip_metadata_api_check      = true
  }
}

Note: Only disable locking if you have single-user access.

Advanced notes

For Terraform Enterprise users: when mounted disk operational mode is enabled, high inode usage can appear as disk-full errors even with space available (check with df -i). PostgreSQL shared memory issues ("No space left on device" during Postgres operations) can be resolved by increasing Docker shared memory size (-v /dev/shm:/dev/shm:rw,size=2g) and tuning shared_buffers and max_locks_per_transaction PostgreSQL parameters. In large monorepos with many workspaces, using Terragrunt with provider caching can further reduce disk overhead. Consider using provider mirrors or Terraform registry mirrors in air-gapped environments to cache providers centrally. Provider plugins can be 500MB+ uncompressed; plan accordingly for ephemeral CI environments.

Frequently asked questions

What does "No space left on device" mean?
This error occurs when Terraform attempts to write files (provider plugins, state, or temporary files) but the filesystem has zero available space. Unlike some errors that may have misleading messages, this one is usually literal - the disk is genuinely full.
How do I fix "No space left on device"?
The "No Space Left on Device" error occurs when Terraform runs out of disk space during initialization, planning, or apply operations. This typically happens in CI/CD environments or when provider caches grow too large. Diagnose disk usage and implement caching strategies to resolve.
What causes "No space left on device"?
CI/CD build agent disk is full from previous builds Provider cache (.terraform directory) grew too large across multiple workspaces Each workspace downloads separate copies of provider plugins
Is the "No space left on device" 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