Problem
When running terraform init, the operation fails to download modules from the Private Module Registry in HCP Terraform or Terraform Enterprise. The command returns the following error message:
error looking up module versions: 403 Forbidden
Prerequisites
- Access to the HCP Terraform or Terraform Enterprise workspace settings.
Cause
This error can occur if a proxy-related environment variable, such as NO_PROXY, is configured as a workspace variable. This variable may interfere with HCP Terraform or Terraform Enterprise's ability to communicate with its internal services, including the Private Module Registry, leading to a 403 Forbidden response.
Solution
To resolve this issue, you must identify and remove the conflicting proxy environment variable from the workspace configuration.
- Navigate to the affected workspace in your HCP Terraform or Terraform Enterprise organization.
- Select the Variables tab.
- Review the list of configured workspace variables and locate any proxy-related variables (e.g.,
HTTP_PROXY,HTTPS_PROXY,NO_PROXY). - Delete the variable that is causing the conflict. In most cases, this will be the
NO_PROXYvariable. - After removing the variable, trigger a new run or execute
terraform initagain from your local command line to confirm that Terraform can now successfully download the modules.
Additional Information
- For more details on managing workspace variables, refer to the official HCP Terraform and Terraform Enterprise documentation.
- To learn more about the Private Module Registry, consult the product documentation.