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.
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.
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 stateS3-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.
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