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

- **ID:** `terraform/provider-version-constraint-failed`
- **领域:** terraform
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Terraform 1.5.0 | active | — | — |
| Terraform 1.6.0 | active | — | — |
| Terraform 1.7.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — The issue is network access, not cached provider versions. The upgrade flag doesn't bypass the 403 error. (95% 失败率)
- **** — If the proxy itself is misconfigured or requires authentication, the 403 persists. The registry might also block known proxy IPs. (65% 失败率)
- **** — The lock file is irrelevant to registry access. Deleting it only removes version constraints, not the network issue. (90% 失败率)
