Error: Failed to install provider
Error: Failed to query available provider packages
Error: Backend initialization required, please run "terraform init"
terraform init downloads providers and configures the backend. When it fails, nothing else works.
Fix 1: Network / Proxy Issues
# β Can't reach registry.terraform.io
# β
Check connectivity
curl -I https://registry.terraform.io
# Behind a proxy:
export HTTP_PROXY=http://proxy:8080
export HTTPS_PROXY=http://proxy:8080
terraform init
Fix 2: Provider Version Conflict
# β Required version doesn't exist
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "= 99.0.0" # π₯ Doesn't exist
}
}
}
# β
Use a valid version constraint
version = "~> 5.0"
Fix 3: Clear Plugin Cache
# β Corrupted cache
# β
Remove and re-download
rm -rf .terraform
rm .terraform.lock.hcl
terraform init
Fix 4: Backend Configuration Changed
# β Backend config changed but not re-initialized
# β
Re-init with migration
terraform init -migrate-state
# Or reconfigure
terraform init -reconfigure
Fix 5: Wrong Terraform Version
# Check version
terraform version
# If provider requires newer Terraform:
# Install the required version
# Or use tfenv/tfswitch
tfenv install 1.7.0
tfenv use 1.7.0
Fix 6: S3 Backend Access Denied
# β Can't access state bucket
# β
Check AWS credentials
aws sts get-caller-identity
aws s3 ls s3://my-terraform-state/
# Check bucket policy and IAM permissions