Problem
When running terraform init against a Terraform Enterprise or HCP Terraform Workspace using the remote backend or cloud configuration, receive error:
│ Error: Error accessing remote module registry
│
│ on main.tf line 39:
│ 39: module "example" {
│
│ Failed to retrieve available versions for module "example" (main.tf:39) from app.terraform.io: error looking up module versions: 401 Unauthorized.Prerequisites
- Local, CLI-driven Terraform execution
- Module located in Private Module Registry
Cause
- Missing valid CLI Configuration File with credentials or credentials created by
terraform login
Solution
- Provide a valid credential token to Terraform Enterprise or HCP Terraform either using
terraform loginor by creating a CLI Configuration File with credentials
Note: it is not sufficient to supply a token argument in the cloud or remote backend configuration to be able to read private module registry modules
Outcome
The terraform init command succeeds without error
Additional Information
https://developer.hashicorp.com/terraform/cli/config/config-file#credentials-1
-
Module Registry shows this requirement: