How to fix Operation failed: failed uploading in Terraform
This error occurs when Terraform fails to upload plan, state, or configuration files to a remote backend or Terraform Enterprise. Common causes include network timeouts, authentication issues, or S3 compatibility problems.
Quick fix
Fixes Operation failed: failed uploading
# Test connectivity to Terraform Enterprise
curl -v https://<TFE_HOSTNAME>
# Test S3 connectivity
aws s3 ls s3://your-bucket/ --region your-region- Verify network connectivity to the remote backend
- Check and renew authentication credentials
- Review Terraform Enterprise version if using TFE v202507-1 or later
- Increase timeout settings for uploads
# Test connectivity to Terraform Enterprisecurl -v https://<TFE_HOSTNAME># Test S3 connectivityaws s3 ls s3://your-bucket/ --region your-regionOperation failed: failed uploading
What this error means
The 'Operation failed: failed uploading' error in Terraform indicates that the system attempted to upload files (plan JSON, state, or configuration) to a remote backend but encountered a failure. This typically happens during terraform plan or terraform apply when using Terraform Cloud, Terraform Enterprise, or S3-compatible backends. The upload failure prevents Terraform from persisting the state remotely, which can lead to state management issues and potential infrastructure synchronization problems.
Typical symptoms
- Terraform plan or apply fails during the upload phase
- Error message shows 'Operation failed: failed uploading' with a URL reference
- Runs fail intermittently, particularly after upgrades or during high network latency
- Timeout errors appear when uploading plan files or state to Terraform Enterprise
- S3 backend operations fail with 'XAmzContentSHA256Mismatch' errors
Common causes
- Network connectivity issues or timeouts between the Terraform CLI and remote backend
- Terraform Enterprise upgraded to v202507-1 or later with SDK changes incompatible with S3-compatible storage
- S3 or S3-compatible backend authentication token expiration during long-running operations (1+ hours)
- Firewall or load balancer blocking or interrupting uploads (TCP/IP level issues)
- Missing or incorrect S3 bucket configuration or permissions
- Corrupted state file or broken symbolic links in Terraform configuration
- Workspace lock state mismatch when using terraform state push
How to fix "Operation failed: failed uploading"
Ensure your system can reach the Terraform backend (TFE URL or S3 endpoint):
# Test connectivity to Terraform Enterprise
curl -v https://<TFE_HOSTNAME>
# Test S3 connectivity
aws s3 ls s3://your-bucket/ --region your-regionIf the connection fails, check firewall rules, VPN connections, and load balancer configurations.
If using AWS S3 with assume_role, AWS credentials can expire during long operations:
# Verify AWS credentials are valid
aws sts get-caller-identity
# For assume_role, check the session token expiration
echo $AWS_SESSION_TOKENFor Terraform Cloud/Enterprise, verify your API token is valid and hasn't expired in your configuration files or environment variables.
If you recently upgraded Terraform Enterprise to v202507-1 or later, you may encounter S3 compatibility issues:
- Check if using S3-compatible storage (DigitalOcean Spaces, Wasabi, etc.)
- Enable additional logging: Set TF_LOG=DEBUG environment variable
- Contact HashiCorp support with the error message containing 'XAmzContentSHA256Mismatch'
export TF_LOG=DEBUG
terraform applyFor S3 backends, increase the HTTP client timeout to handle slower networks:
terraform {
backend "s3" {
bucket = "my-bucket"
key = "terraform.tfstate"
region = "us-east-1"
# Note: S3 backend doesn't directly support timeout config,
# but you can use environment variables
}
}Set environment variable for HTTP timeout:
export AWS_MAX_ATTEMPTS=5
export AWS_RETRY_MODE=adaptive
terraform applyIf using Terraform Cloud with the remote backend, verify workspace locking state:
# If you see 'Conflict' errors about locking, your workspace state may be misaligned
# Verify the workspace is not locked by another run
terraform state lock
# If state file is corrupted locally, recover from remote:
terraform state pull > backup.tfstate
terraform init -reconfigureWhen Terraform fails to upload, it writes state locally to 'errored.tfstate':
# List files to check for errored state
ls -la | grep errored
# If found, push the errored state back:
terraform state push errored.tfstate
# Do NOT run terraform apply again without resolving the upload issue,
# as this creates a forked stateAdvanced notes
S3-Compatible Storage Issues: When using S3-compatible backends (DigitalOcean Spaces, Wasabi, OVHCloud), the 'XAmzContentSHA256Mismatch' error indicates the backend server does not support AWS Signature Version 4 signing with Content-SHA256 headers. This became an issue after TFE v202507-1 updated its SDK. Workaround: Contact your storage provider or HashiCorp support for compatibility updates.
Terraform Enterprise Agent Failures: For TFC/TFE runs executed by agents, if the agent detects an errored.tfstate file, it automatically uploads it to the platform. Use the 'Recover a failed state upload' API to retrieve it.
Workspace Lock Prevention: Always ensure the workspace lock is properly released before pushing state manually. A common mistake is running terraform state push errored.tfstate while the workspace is locked, causing 'Conflict' errors.
Frequently asked questions
- What does "Operation failed: failed uploading" mean?
- The 'Operation failed: failed uploading' error in Terraform indicates that the system attempted to upload files (plan JSON, state, or configuration) to a remote backend but encountered a failure. This typically happens during terraform plan or terraform apply when using Terraform Cloud, Terraform Enterprise, or S3-compatible backends. The upload failure prevents Terraform from persisting the state remotely, which can lead to state management issues and potential infrastructure synchronization problems.
- How do I fix "Operation failed: failed uploading"?
- This error occurs when Terraform fails to upload plan, state, or configuration files to a remote backend or Terraform Enterprise. Common causes include network timeouts, authentication issues, or S3 compatibility problems.
- What causes "Operation failed: failed uploading"?
- Network connectivity issues or timeouts between the Terraform CLI and remote backend Terraform Enterprise upgraded to v202507-1 or later with SDK changes incompatible with S3-compatible storage S3 or S3-compatible backend authentication token expiration during long-running operations (1+ hours)
- Is the "Operation failed: failed uploading" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.