IBM Support

CLI-driven remote run: "error looking up module versions: 401 Unauthorized"

Troubleshooting


Problem

When running terraform init for a Terraform Enterprise or HCP Terraform workspace using the remotebackend or cloudconfiguration, you receive a 401 Unauthorized 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

  • You are using a local, CLI-driven Terraform execution workflow.
  • The module referenced in your configuration is located in a Private Module Registry.

Cause

This error occurs because Terraform does not have a valid API token to authenticate to the Private Module Registry. The CLI requires credentials stored locally, either from running terraform login or from a credentials block in the CLI configuration file.

Supplying a token argument directly within the cloud or remote configuration block is not sufficient for authenticating to the Private Module Registry.

Solution

To resolve this issue, you must provide a valid API token by authenticating the Terraform CLI to Terraform Enterprise or HCP Terraform. You can do this in one of two ways:

  1. Use the terraform login command. This is the recommended method, as it securely stores the token for you.

    $ terraform login
  2. Manually create a CLI configuration file. You can create a CLI configuration file with credentials that contains a valid token.

After authenticating with either method, run terraform init again. The command should succeed without error.

Additional Information

  • The requirement to authenticate is often displayed in the HCP Terraform or Terraform Enterprise UI, as shown below.

    Terraform Module Registry UI showing the 'terraform login' command is required for private modules

  • For more details on credential storage, refer to the documentation on Terraform CLI Credentials.

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB77","label":"Automation Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSGH5YK","label":"IBM Terraform Self-Managed"},"ARM Category":[{"code":"","label":""}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Version(s)"}]

Historical Number

43424789279379

Document Information

Modified date:
16 March 2026

UID

ibm17266070