terraform network_error ai_generated true

错误:无法查询可用的 provider 包:无法检索 provider hashicorp/aws 的可用版本列表:registry.terraform.io 返回状态码 403 Forbidden

Error: Failed to query available provider packages: could not retrieve the list of available versions for provider hashicorp/aws: the provider registry at registry.terraform.io returned status 403 Forbidden

ID: terraform/provider-version-constraint-failed

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
1证据数
2024-06-10首次发现

版本兼容性

版本状态引入弃用备注
Terraform 1.5.0 active
Terraform 1.6.0 active
Terraform 1.7.0 active

根因分析

对 Terraform 注册表的网络访问被防火墙或代理阻止,或者注册表的 API 凭据缺失或无效。

English

Network access to the Terraform registry is blocked by a firewall or proxy, or API credentials for the registry are missing or invalid.

generic

官方文档

https://developer.hashicorp.com/terraform/cli/config/config-file#provider-installation

解决方案

  1. 配置 Terraform 使用可访问的本地镜像或私有注册表。在 .terraformrc 或 terraform.rc 文件中添加 provider_installation 块。
  2. 确保网络访问:将 registry.terraform.io 添加到防火墙/代理的白名单中,或使用具有正确身份验证的企业代理。
  3. 使用已缓存在本地文件系统镜像中的 provider 版本。在可访问网络的机器上运行 terraform providers mirror /path/to/mirror。

无效尝试

常见但无效的做法:

  1. 95% 失败

    The issue is network access, not cached provider versions. The upgrade flag doesn't bypass the 403 error.

  2. 65% 失败

    If the proxy itself is misconfigured or requires authentication, the 403 persists. The registry might also block known proxy IPs.

  3. 90% 失败

    The lock file is irrelevant to registry access. Deleting it only removes version constraints, not the network issue.