terraform install_error ai_generated true

Error: Failed to download module: could not download module: source not found

ID: terraform/terraform-init-module-source-error

Also available as: JSON · Markdown · 中文
87%Fix Rate
84%Confidence
1Evidence
2023-08-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.5.0 active — — —
1.6.0 active — — —
1.7.0 active — — —
1.8.0 active — — —

Root Cause

The module source URL or path specified in the configuration is incorrect, unreachable, or requires authentication.

generic

中文

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

Official Documentation

https://developer.hashicorp.com/terraform/language/modules/sources

Workarounds

  1. 90% success Verify the module source in the configuration. For example, if using a Git repo, ensure the URL is correct: module "vpc" { source = "git::https://github.com/org/terraform-aws-vpc.git?ref=v1.0.0" }. Test the URL in a browser or with git clone.
    Verify the module source in the configuration. For example, if using a Git repo, ensure the URL is correct: module "vpc" { source = "git::https://github.com/org/terraform-aws-vpc.git?ref=v1.0.0" }. Test the URL in a browser or with git clone.
  2. 85% success If the module is from the Terraform Registry, ensure the source is in the format "namespace/name/provider". Run terraform init -from-module=namespace/name/provider to test.
    If the module is from the Terraform Registry, ensure the source is in the format "namespace/name/provider". Run terraform init -from-module=namespace/name/provider to test.
  3. 80% success For local modules, ensure the path is relative to the root module and exists. Use an absolute path for testing: source = "/home/user/modules/my-module".
    For local modules, ensure the path is relative to the root module and exists. Use an absolute path for testing: source = "/home/user/modules/my-module".

中文步骤

  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"。

Dead Ends

Common approaches that don't work:

  1. Run terraform init -upgrade without checking the source URL. 90% fail

    If the source URL is wrong, upgrading won't fix it; it will just try the same wrong URL again.

  2. Set GIT_TERMINAL_PROMPT=1 and hope for an interactive prompt. 70% fail

    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.

  3. Delete the .terraform directory and run terraform init again. 95% fail

    This only clears the local cache; it doesn't fix the invalid source reference.