Self-Healing CI: Auto-Retrying a Terraform Provider Download Timeout
A terraform init that cannot query provider packages failed to reach registry.terraform.io or releases.hashicorp.com: the constraint in your configuration is fine.
The problem
terraform init fails before any plan or apply, reporting that it could not retrieve the list of available versions for a provider, or could not install one. The version constraint is satisfiable and the provider exists. The registry or the release host was unreachable for the duration of the request.
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/awsWhy it happens
init is the only stage that reaches the provider registry, so every network fault in the whole run is concentrated into one short window near the start of the job.
Terraform formats this error across several indented lines, so log scrapers that match line by line often miss it and report the job as failing for an unknown reason.
The manual fix
Manual mitigations for a provider download failure:
- Re-run terraform init to retry the download.
- Use a provider mirror or a filesystem mirror so init resolves locally.
- Cache the .terraform directory between runs so unchanged providers are not re-fetched.
terraform init -upgrade=false -input=falseHow this gets automated
This failure is worth healing precisely because of where it lands: init runs before plan, so a transient blip here costs the entire run and any queue time in front of it, without a single resource having been touched. Retrying init is also safe in a way retrying apply is not, because it changes nothing outside the working directory. A self-healing pipeline retries the step with backoff and leaves genuine constraint errors, which read differently, to fail.