# 错误：下载模块失败：无法下载模块：源未找到

- **ID:** `terraform/terraform-init-module-source-error`
- **领域:** terraform
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 87%

## 根因

配置中指定的模块源 URL 或路径不正确、无法访问或需要身份验证。

## 版本兼容性

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

## 解决方案

1. ```
   验证配置中的模块源。例如，如果使用 Git 仓库，请确保 URL 正确：module "vpc" { source = "git::https://github.com/org/terraform-aws-vpc.git?ref=v1.0.0" }。在浏览器中或使用 git clone 测试 URL。
   ```
2. ```
   如果模块来自 Terraform Registry，请确保源格式为 "namespace/name/provider"。运行 terraform init -from-module=namespace/name/provider 进行测试。
   ```
3. ```
   对于本地模块，请确保路径相对于根模块且存在。使用绝对路径进行测试：source = "/home/user/modules/my-module"。
   ```

## 无效尝试

- **Run terraform init -upgrade without checking the source URL.** — If the source URL is wrong, upgrading won't fix it; it will just try the same wrong URL again. (90% 失败率)
- **Set GIT_TERMINAL_PROMPT=1 and hope for an interactive prompt.** — This only helps if the source is a private Git repo and you need to enter credentials, but the error says 'source not found', not authentication failure. (70% 失败率)
- **Delete the .terraform directory and run terraform init again.** — This only clears the local cache; it doesn't fix the invalid source reference. (95% 失败率)
