Skip to content

SAIFTRBL0018 ยท permalink

Terraform Init fails with 401 Unauthorized from tf.pulumi.com

If terraform init fails with 401 Unauthorized from tf.pulumi.com, the pipeline job has no Pulumi token. Check whether the failing job ran the Pulumi Cloud OIDC Login step. If it did not, the run was queued before that step reached pipeline-templates. Queue a new run of the pipeline. Re-running a stage on the old run fails the same way every time.


๐Ÿšจ Symptom

Terraform Init fails with one error block per module that resolves from tf.pulumi.com:

Error: Error accessing remote module registry

  on .terraform/modules/oktaApp-Api/test-token-generator/locals.tf line 1:
   1: module "okta-data" {

Failed to retrieve available versions for module "okta-data"
(.terraform/modules/oktaApp-Api/test-token-generator/locals.tf:1) from
tf.pulumi.com: error looking up module versions: 401 Unauthorized.

The module names and paths change with the project, but every block ends with from tf.pulumi.com: error looking up module versions: 401 Unauthorized. Modules from app.terraform.io are not affected.

Check whether the failing job ran the login step. From any directory, run saif pipeline logs with the build URL, the job name from the failure, and the step's exact display name, including the emoji:

saif pipeline logs '<build-url>' --stage '<stage name>' --job '<failing job name>' --step '๐Ÿ”‘ Pulumi Cloud OIDC Login (saif-corp)' --tail 5
  • If it prints No log entries found matching the specified filters., the job had no login step and the run is stale. Use the Fix.
  • If it prints the step's log and the step succeeded, this article does not explain the failure. Check that log and the pulumi-registry service connection, then report it.

The output also lists the build's templates repository commit, which is the pipeline-templates version the run uses.


๐Ÿ“Œ Applies to

Every Forge Terraform workspace runs through Forge Azure DevOps pipelines on SAIF/pipeline-templates, so this article covers only those pipelines. It applies when the Terraform root's modules, or the Forge modules they call, install from tf.pulumi.com/saif-corp/.... Since Forge 3.10.0, Forge's own nested module sources resolve from tf.pulumi.com even when the root installs the parent module from app.terraform.io, so pipeline runs for projects on 3.10.0 or later need the login step. See the 3.10.0 release notes and 3.10.1 release notes.

It applies to runs on SAIF/pipeline-templates releases/v3 that resolved their templates before the login step covered the job:

Change in releases/v3 Merged Adds the login step to
PR 13804 2026-10-02 The terraform component
PR 14021 2026-10-08 The legacy terraform-cloud-cli steps

Azure DevOps expands templates when a run is queued (Pipeline run sequence), so a run keeps the template version it was queued with. Re-running a stage, including one whose approval expired or one that was skipped, does not pick up newer templates. Build 208273 showed this: its production stage ran three times, the last two on 2026-10-16, and all three used the template commit from its 2026-09-29 queue time.

Prerequisites and safety

  • Permission to queue the pipeline and to approve each environment it deploys to.
  • The SAIF CLI for the commands below.
  • A new run starts from the first stage, so it goes through Test, QA, and UAT and their approvals again. It deploys the latest commit on the branch you pick, which might include changes the old run did not have. Check what changed since the old run's commit before you promote it.
  • Do not keep re-running the failed stage. The failure is deterministic for that run.

โœ… Fix

You don't need to set up a token. pipeline-templates handles the login, so the fix is to get a run that has the login step.

  1. Confirm the run is stale with the saif pipeline logs check in Symptom. You can also compare the run's queue time with the table in Applies to.
  2. Cancel or abandon the old run so nobody re-runs it again.
  3. Queue a new run of the same pipeline from the branch you want to deploy, usually main:

    saif pipeline run --repo '<repository-name>' --pipeline-name '<pipeline-name>' --branch main
    

    If the pipeline name is wrong, the command lists the repository's pipelines instead of queuing a run. You can also queue the run from Azure DevOps.

  4. Promote the new run through each environment as usual.


๐Ÿ”ฌ Verify

In the new pipeline run, the job shows Pulumi Cloud OIDC Login (saif-corp) before Terraform Init, and Terraform Init downloads the modules:

Downloading tf.pulumi.com/saif-corp/<module>/<system> <version> for <module-label>...
Terraform has been successfully initialized!

If the 401 persists with the login step present and successful, check that step's log and report it.


๐Ÿง  Cause

Starting with Forge 3.10.0, Forge modules and their nested sources install from the Pulumi Cloud private registry at tf.pulumi.com. The registry accepts a Pulumi access token, and terraform init reads the token for that host from the TF_TOKEN_tf_pulumi_com environment variable (Pulumi: Authenticate).

The Pulumi Cloud OIDC Login step in pipeline-templates supplies it. The step uses the pulumi-registry service connection to log in to Pulumi Cloud with the pipeline's OIDC identity, then writes the resulting access token to TF_TOKEN_tf_pulumi_com for the steps that follow, including Terraform Init. No long-lived token is stored in the project.

A pipeline run fixes its templates at queue time. A run queued before the login step existed has no such step in any stage, including stages that run days or weeks later after an approval or a manual re-run. When that run reaches terraform init on a project that resolves Forge 3.10.0 or later, the registry rejects the anonymous request with 401 Unauthorized.

An approval that expires skips the stage, and re-running it creates a new approval without refreshing the templates. See Approval Expiration for why we recommend replacing a run with an expired approval with a new run.