---
title: Migrate Credentials from TFC Variable Sets to Pulumi ESC
description: Move Terraform consumers off Terraform Cloud variable sets and onto Pulumi ESC environments for Okta, Dynatrace, and AWS credentials.
---

# Migrate Credentials from TFC Variable Sets to Pulumi ESC

!!! danger "State Safety Check: Required Before Starting"
    This migration changes where your pipeline runs Terraform and where it gets credentials. Before you change anything, confirm these checks:

    1. **Dry-run first**: Always run `terraform plan` before `terraform apply`. If the plan shows unexpected creates, replaces, or destroys, stop and investigate.
    2. **State backup**: Confirm the TFC workspace has a recent state version before you cut over.
    3. **One runner**: Freeze the old TFC pipeline and workspace before you copy state, and keep them frozen through cutover. An old apply after the copy leaves the Pulumi Cloud state stale even if the two pipelines never overlap. See [Step 7](#step-7-move-state-from-tfc-to-pulumi-cloud).

    If any of these checks cannot be satisfied, do not continue.

Terraform consumers that read credentials from Terraform Cloud (TFC) variable sets move to Pulumi ESC. The pipeline environment selects one ESC environment for each deployment, and that environment exports provider-native environment variables. Your Terraform code stops declaring credential variables and lets each provider read its own environment.

The Platform team runs this migration on behalf of teams, and we expect to script most of it. The steps stay generic so anyone can follow them by hand against an existing Forge Terraform repo that uses TFC variable sets such as `okta-external-np`, `okta-external-prod`, `dynatrace-dev`, `dynatrace-prod`, or `aws-dns-<env>`. This work is part of [saif-corp/platform-engineering#15](https://github.com/saif-corp/platform-engineering/issues/15). Forge app repos (API, web, subscription, and auth) also move their pipelines to new root templates and drop `infra/bootstrap`, tracked in [saif-corp/platform-engineering#24](https://github.com/saif-corp/platform-engineering/issues/24).

This guide covers Okta, Dynatrace, and AWS credentials. It does not change Azure provider authentication or any Azure inputs in your Terraform code. Step 6 does move the pipeline's Azure service connections, as its warning explains.

[TOC]

---

## Overview of Changes

| Area                  | Before                                                                 | After                                                                     |
| --------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| Credential source     | TFC variable sets attached to the workspace                            | One Pulumi ESC environment, `saif/<env>`, selected by the pipeline environment |
| Credential delivery   | `TF_VAR_*` and Terraform input variables                               | Provider-native environment variables only, no `TF_VAR_*`                 |
| Provider blocks       | Providers configured from Terraform variables                          | Empty provider blocks, for example `provider "okta" {}`                   |
| AWS authentication    | `TFC_AWS_PROVIDER_AUTH` and `TFC_AWS_RUN_ROLE_ARN`                      | Short-lived `AWS_*` credentials from ESC OIDC                             |
| External-auth inputs  | Caller passes tenant and test token whitelist                          | `iac-okta-modules` external-auth modules own both                         |
| Pipeline              | TFC-backed Terraform pipeline                                          | `terraform-pulumicloud` deployment service on `provider: saif` environments, which supply `PulumiEscEnvironment` |
| Terraform state       | TFC workspace                                                          | Pulumi Cloud stack through the Terraform remote backend API, still HCL on the Terraform CLI |
| Backend block         | `cloud { organization = "SAIFCorp" workspaces { ... } }`               | `cloud { hostname = "tf.pulumi.com" organization = "saif-corp" }`, no `workspaces` block |
| Module registry       | `app.terraform.io/SAIFCorp/...`                                        | `tf.pulumi.com/saif-corp/...`                                             |
| Bootstrap             | `infra/bootstrap` creates the TFC workspaces                           | Removed. Step 7 creates the stacks                                        |
| Forge app pipelines   | `azure-dotnet-api-v3.yml`, `azure-react-web-v3.yml`, `azure-dotnet-sub-v2.yml`, `azure-auth.yml`, with the `TerraformCloud` and `Dynatrace` variable groups | `api-service.yml`, `web-service.yml`, `app-sub.yml`, `app-auth.yml` and their `-pr` variants, without `TerraformCloud` or `Dynatrace` |

!!! warning "Breaking Change"
    Upgrading the `iac-okta-modules` external-auth modules changes test token behavior for callers that passed an empty whitelist. See [Behavior change for empty whitelists](#behavior-change-for-empty-whitelists) before you upgrade.

---

## ESC Environment Model

Each pipeline environment binds exactly one ESC environment, `saif/<env>`, and `terraform-pulumicloud` runs every Terraform command for that environment under it. That environment composes the per-provider leaf environments, so you never bind a leaf directly. You don't choose the binding per deployment. [Step 6](#step-6-move-the-pipeline-to-terraform-pulumicloud) explains where it comes from.

```mermaid
flowchart LR
    stack["Pipeline environment"] --> saif["saif/&lt;env&gt;"]
    saif --> azure["azure/&lt;env&gt;"]
    saif --> aws["aws/&lt;env&gt;"]
    saif --> okta["okta-ext/non-prod or okta-ext/prod"]
    saif --> dt["dynatrace/dev or dynatrace/prod"]
```

| `saif/<env>`          | Azure                     | AWS                 | Okta external      | Dynatrace        |
| --------------------- | ------------------------- | ------------------- | ------------------ | ---------------- |
| `development-sandbox` | `azure/development-sandbox` | Not included      | Not included       | Not included     |
| `shared-services`     | `azure/shared-services`   | Not included        | Not included       | Not included     |
| `platformdev`         | `azure/platformdev`       | `aws/platformdev`   | `okta-ext/non-prod` | `dynatrace/dev` |
| `test`                | `azure/test`              | `aws/test`          | `okta-ext/non-prod` | `dynatrace/dev` |
| `qa`                  | `azure/qa`                | `aws/qa`            | `okta-ext/non-prod` | `dynatrace/dev` |
| `uat`                 | `azure/uat`               | `aws/uat`           | `okta-ext/non-prod` | `dynatrace/dev` |
| `prod`                | `azure/prod`              | `aws/prod`          | `okta-ext/prod`    | `dynatrace/prod` |

`development-sandbox` and `shared-services` are Azure only. `saif/<env>` composes the `azure/<env>` leaf, but this guide does not change how Terraform authenticates to Azure. Leave Azure provider configuration and Azure inputs as they are.

The pipeline binds only the `platformdev`, `test`, `qa`, `uat`, and `production` environments today, because only those have saif environment files in `SAIF/pipeline-templates`. `production` binds `saif/prod`. `development-sandbox` and `shared-services` have no saif environment file, so `terraform-pulumicloud` can't run there yet.

!!! tip "Dynatrace-only stacks"
    A stack that only manages Dynatrace gets its tenant from the pipeline environment. `platformdev`, `test`, `qa`, and `uat` reach `dynatrace/dev`, and `production` reaches `dynatrace/prod`.

---

## What ESC Exports

ESC exports provider-native environment variables only. It does not export any `TF_VAR_*` values, so Terraform input variables for credentials no longer receive a value. This section lists the Okta, Dynatrace, and AWS exports that this migration depends on. It does not document Azure exports because this migration does not change Azure credentials.

### Okta

| Environment variable      | Notes                         |
| ------------------------- | ----------------------------- |
| `OKTA_ORG_NAME`           |                               |
| `OKTA_BASE_URL`           |                               |
| `OKTA_API_CLIENT_ID`      |                               |
| `OKTA_API_PRIVATE_KEY_ID` |                               |
| `OKTA_API_PRIVATE_KEY`    |                               |
| `OKTA_API_SCOPES`         | Comma-separated list (CSV)    |

The same environment also sets Pulumi config under the `okta:*` namespace for Pulumi programs. In Pulumi config, `okta:scopes` is an array, not a CSV string.

### Dynatrace

| Environment variable  |
| --------------------- |
| `DT_CLIENT_ID`        |
| `DT_CLIENT_SECRET`    |
| `DT_ACCOUNT_ID`       |
| `DYNATRACE_ENV_URL`   |
| `DYNATRACE_API_TOKEN` |

### AWS

ESC issues short-lived credentials through OIDC and exports `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_SESSION_TOKEN`, and `AWS_REGION`. These replace the TFC dynamic credential settings `TFC_AWS_PROVIDER_AUTH` and `TFC_AWS_RUN_ROLE_ARN`.

---

## Old-to-New Mapping

| Old                                                                                                   | New                                                                                                                       | Notes                                                                                                                                                  |
| ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Terraform variables `okta_org_name`, `okta_base_url`, `okta_client_id`, `okta_private_key_id`, `okta_pk`, `okta_scopes` | Remove them. Use `provider "okta" {}`                                                                        | This changes the credential source. It is not a rename. The provider reads the `OKTA_*` variables from ESC                                            |
| `TestTokenGeneratorGroupWhitelist` / `test_token_generator_group_whitelist`                           | Remove from callers                                                                                                       | The `iac-okta-modules` external-auth modules now own the fixed non-prod group `Test Token Generator TestUser`. Prod has no test token or CLI flows    |
| External-auth `tenant` / `Tenant` input                                                               | Remove from callers. The module uses the literal `ext`                                                                    | The JWT tenant-origin claim and the `TenantOrigin` output do not change                                                                                |
| Workspace naming tenant metadata                                                                      | Keep it                                                                                                                   | Only the external-auth module input goes away                                                                                                          |
| Azure tenant inputs and corp business roles                                                           | Unchanged                                                                                                                 |                                                                                                                                                        |
| `is_production`                                                                                       | Unchanged                                                                                                                 | The pipeline still supplies it                                                                                                                         |
| TFC variable sets `okta-external-np`, `okta-external-prod`, `dynatrace-dev`, `dynatrace-prod`, `aws-dns-<env>` | ESC leaf environments, reached through `saif/<env>`                                                              | Detach the variable sets only after cutover checks pass                                                                                                |

### Behavior change for empty whitelists

Before this change, a caller that passed `[]` for the test token whitelist disabled both non-prod flows. After you upgrade the external-auth module, both non-prod flows are enabled for the module-owned `Test Token Generator TestUser` group. If your stack relied on `[]` to turn those flows off, talk to the Platform team before you upgrade.

---

## Migrate an Existing Repo

Follow these steps in order for each repo. Steps 4 through 7 form one cutover sequence. The repo cannot plan between them because provider credentials, the ESC binding, and state move separately, so run the next plan in Step 8. If any check in a step fails, stop and do not continue to the next step.

Collect these inputs before you start:

- The repo and each Terraform root module (stack) it deploys
- The TFC workspace and attached variable sets for each stack
- The pipeline environments each stack deploys to. Each one selects its `saif/<env>` binding, per [ESC Environment Model](#esc-environment-model)
- The workspace name the new pipeline computes for each stack, in the form `<project>_<stack>`. Step 7 creates a Pulumi stack under that name

### Step 1: Create a branch

```bash
git checkout -b feat/migrate-to-pulumi-esc
```

### Step 2: Upgrade `iac-okta-modules`

Skip this step if the repo does not use the `iac-okta-modules` external-auth modules.

Bump the module to the release noted in the `iac-okta-modules` CHANGELOG that standardizes tenant and whitelist. Then remove the `tenant` and `test_token_generator_group_whitelist` arguments from each external-auth module call.

=== "Before"

    ```hcl
    module "external_auth" {
      source = "..."

      tenant                              = var.tenant
      test_token_generator_group_whitelist = var.test_token_generator_group_whitelist
      # other inputs unchanged
    }
    ```

=== "After"

    ```hcl
    module "external_auth" {
      source = "..."

      # other inputs unchanged
    }
    ```

Read [Behavior change for empty whitelists](#behavior-change-for-empty-whitelists) before you merge this step.

### Step 3: Choose regeneration or targeted edits

Forge templates generate empty `provider "okta" {}` blocks without the external-auth `tenant` and whitelist inputs. Starting with the Forge release that ships the Pulumi Cloud app pipelines, they also generate the Pulumi Cloud `cloud` block and pipelines that extend the root templates in Step 6. Older Forge releases generate TFC-backed `cloud` blocks and pipeline YAML. Check the [release notes](../../release-notes/index.md) for the release.

- **Before that release**: Do not regenerate. Make the targeted edits in Steps 4 through 6.
- **After that release**: Regenerate the pipeline files, compare the `*.generated.tf` files against a freshly scaffolded template, and confirm the result matches Steps 4 through 6. If regeneration would overwrite hand-maintained changes, make the targeted edits instead.

A Forge upgrade only touches generated pipeline files:

| Item                              | What a Forge upgrade does                                              |
| --------------------------------- | ---------------------------------------------------------------------- |
| `.azdo/*.yml`, `.azdo/vars/*.yml` | `aspire publish` deletes and rewrites them (except `azure-pipelines-pr-slot-cleanup.yml`). Manual edits are lost |
| `infra/**/*.tf`                   | Not touched. Edit them by hand                                         |
| `infra/bootstrap`                 | Not removed. Delete it by hand                                         |
| TFC state                         | Not moved. See Step 7                                                  |
| Azure DevOps pipeline definitions | Unchanged. They pick up the new YAML on the next push                  |

!!! warning "Do not push regenerated pipelines before Step 7"
    The regenerated pipelines read state from Pulumi Cloud. Pushing them to `main` before Step 7 runs them against a stack that does not exist yet.

Forge app repos also make these edits in every root (`infra/api`, `infra/web`, `infra/sub`, `infra/auth/corp`, `infra/auth/ext/app`, `infra/auth/ext/okta-client`, `infra/auth/ext/user`):

1. Move module sources from `app.terraform.io/SAIFCorp/<name>/<provider>` to `tf.pulumi.com/saif-corp/<name>/<provider>`, and replace deprecated modules:

    | Old module                      | New module                      | Version constraint   |
    | ------------------------------- | ------------------------------- | -------------------- |
    | `saif-apiservice/azure`         | `api-service/saif`              | `>= 3.11.0, < 4.0.0` |
    | `saif-webapp/azure`             | `web-service/saif`              | `>= 3.11.0, < 4.0.0` |
    | `application-permissions/saif`  | `application-permissions/saif`  | `>= 3.11.0, < 4.0.0` |
    | `event-subscriber-service/saif` | `event-subscriber-service/saif` | `>= 3.11.0, < 4.0.0` |

    !!! warning "Prerelease versions"
        `saif-apiservice/azure` and `saif-webapp/azure` do not exist on `tf.pulumi.com`, and the lowest published version of the other modules is `3.10.0`. Prerelease pins such as `3.7.5-alpha.*` are not published. Confirm that the fix your prerelease carried is in the version you move to before you plan.

2. Delete `infra/bootstrap`. Step 7 creates the stacks that bootstrap used to create.

The `cloud` block itself changes in Step 7, after you pull the TFC state.

### Step 4: Switch provider blocks

Replace variable-driven provider configuration with empty provider blocks. Each provider reads its own environment variables from ESC.

=== "Before"

    ```hcl
    provider "okta" {
      org_name       = var.okta_org_name
      base_url       = var.okta_base_url
      client_id      = var.okta_client_id
      private_key_id = var.okta_private_key_id
      private_key    = var.okta_pk
      scopes         = var.okta_scopes
    }
    ```

=== "After"

    ```hcl
    provider "okta" {}
    ```

Apply the same pattern to the Dynatrace and AWS providers. Keep any non-credential settings your stack needs, such as provider aliases.

### Step 5: Remove credential variables

Delete the variable declarations and any `*.tfvars` or pipeline entries for `okta_org_name`, `okta_base_url`, `okta_client_id`, `okta_private_key_id`, `okta_pk`, `okta_scopes`, and `test_token_generator_group_whitelist`. Leave `is_production` in place.

Do not delete `tenant` everywhere. Step 2 removes only the external-auth module argument. Other code still uses `var.tenant`, for example the `saif-appservices` module call and `var.tenant == "ext"` validation checks in generated Terraform. In each root module, search for `var.tenant` and delete the `tenant` declaration and its pipeline entry only when no references remain.

### Step 6: Move the pipeline to `terraform-pulumicloud`

!!! tip "Forge app repos"
    API, web, subscription, and auth repos skip the orchestrator edits below. Their pipelines extend root templates in `SAIF/pipeline-templates` (`api-service.yml`, `web-service.yml`, `app-sub.yml`, `app-auth.yml`, and their `-pr` variants) that already use `terraform-pulumicloud` with `provider: saif`. Regenerate them by running `aspire publish --output-path ./` from the application repository root, where `.azdo/` lives (not the AppHost directory), or copy them from a freshly scaffolded template. Their auth stacks deploy from the api and web pipelines by default, and the separate auth pipeline stays available for auth-only changes. Drop the `TerraformCloud` and `Dynatrace` variable groups. See [Root templates and the Pulumi Cloud backend](../../reference/pipelines.md) for the parameters and [Publish with Aspire](../../build/deploy/aspire-publish.md) for `WithSlotDeployment`, `WithGitTag`, and `WithBlueGreen`.

`terraform-pulumicloud` is a deployment service in the Azure DevOps repo `SAIF/pipeline-templates`, not a Forge template. Its source lives in [`v2/deployments/terraform-pulumicloud/`](https://dev.azure.com/SAIFCorporation/SAIF/_git/pipeline-templates?path=/v2/deployments/terraform-pulumicloud&version=GBreleases/v3).

Make sure the pipeline extends `SAIF/pipeline-templates` at `refs/heads/releases/v3`:

```yaml
resources:
  repositories:
    - repository: templates
      type: git
      name: SAIF/pipeline-templates
      ref: refs/heads/releases/v3
```

Set `provider: saif` on every entry in the orchestrator's `environments` parameter. The saif environment files under [`v2/environments/saif/`](https://dev.azure.com/SAIFCorporation/SAIF/_git/pipeline-templates?path=/v2/environments/saif&version=GBreleases/v3) supply the ESC binding, and the `azure` files don't. The default list in `v2/orchestrator.yml` uses `provider: azure`, so pass your own list. Keep the environments, `dependsOn` order, and `environmentGroup` values your pipeline uses today, and change only `provider`:

```yaml
environments:
  - name: platformdev
    displayName: 'Platform Dev'
    provider: saif
    dependsOn: []
    environmentGroup: platform
  - name: test
    displayName: 'Test'
    provider: saif
    dependsOn: []
    environmentGroup: product
  - name: qa
    displayName: 'QA'
    provider: saif
    dependsOn: [test]
    environmentGroup: product
  - name: uat
    displayName: 'UAT'
    provider: saif
    dependsOn: [qa]
    environmentGroup: product
  - name: production
    displayName: 'Production'
    provider: saif
    dependsOn: [uat]
    environmentGroup: product
```

Each saif environment file sets `PulumiEscEnvironment` to `saif-corp/saif/<env>`, and `production.yml` sets `saif-corp/saif/prod`. `v2/orchestrator.yml` forwards that value into each deployment's config through its `deploymentEnvironmentVariables` parameter. If your pipeline replaces that list, keep the `PulumiEscEnvironment` entry.

!!! warning "`provider: saif` changes Azure service connections"
    `provider` belongs to the environment entry, so every deployment in the pipeline moves with it. Deployments that read `config.AzureServiceConnection` switch from `Azure-<Env>` to the federated `iac-<env>` connection, including non-Terraform deployments such as slot swaps and static content uploads. If `iac-<env>` lacks a right a deployment needs, ask the Platform team to grant it rather than falling back to `Azure-<Env>`.

In the orchestrator deployment config, set `config.service` to `terraform-pulumicloud`:

```yaml
config:
  service: terraform-pulumicloud
```

The service defaults to Terraform `1.16.6`, the same version that writes the state in Step 7. If the deployment sets `config.terraformVersion`, remove it or set it to `1.16.6` or later. HashiCorp's [v1.x compatibility promises](https://developer.hashicorp.com/terraform/language/v1-compatibility-promises) cover upgrades only and say a downgrade isn't guaranteed to read newer state snapshot formats, so don't let the pipeline run an older Terraform than the one that wrote the state. The deployment's `type`, `stack`, and `collapseNonProduction` settings decide the workspace name, which Step 7 needs.

Remove `config.escEnvironment` if an earlier version of this guide had you add it. The service no longer reads it, per its [`variables/common.yml`](https://dev.azure.com/SAIFCorporation/SAIF/_git/pipeline-templates?path=/v2/deployments/terraform-pulumicloud/variables/common.yml&version=GBreleases/v3), and it ignores a stale value instead of failing, so the value only misleads the next reader. Don't set `PulumiEscEnvironment` in `config` either, because the environment file owns it.

If no binding resolves, the pipeline's `pulumi-login` step fails before it touches the backend, with an error that starts `No ESC environment`. Global-stage deployments, `development-sandbox`, and `shared-services` have no saif environment file, so they can't use `terraform-pulumicloud` yet. Contact the Platform team instead of working around the missing binding.

Remove any `TFC_AWS_PROVIDER_AUTH` and `TFC_AWS_RUN_ROLE_ARN` settings.

### Step 7: Move state from TFC to Pulumi Cloud

Skip this step if the stack's state already lives in Pulumi Cloud. Otherwise, move it before the first pipeline run. For Forge app repos, the Platform team scripts this step with `tools\migrate_tfc_to_pulumi.ps1` in `saif-corp/platform-engineering`, following the runbook in `tools\migrations\README.md`. The substeps below show what the move involves. A run that can't find the stack skips its Terraform operations and still reports success. With `config.createWorkspace: true`, the run creates a new, empty stack instead and plans to create every resource.

Pulumi Cloud implements the Terraform remote backend API, so the Terraform code stays HCL and keeps running on the Terraform CLI. Each TFC workspace maps to one Pulumi Cloud stack, named `<project>_<stack>` on the Terraform side. The pipeline computes that name from the deployment config and treats the text before the first underscore as the Pulumi project:

| Deployment `type`   | Workspace name              |
| ------------------- | --------------------------- |
| `environment`       | `<projectId>_<env>`         |
| `named-environment` | `<projectId>_<stack>-<env>` |
| `static`            | `<projectId>_<stack>`       |

`type` defaults to the deployment name. `<env>` is the environment's short name, for example `test` or `prod`, and becomes `prod` or `np` when `collapseNonProduction` is `true`. For example, a `named-environment` deployment with `projectId: myapp` and `stack: api` uses `myapp_api-test` in `test`, which is the Pulumi stack `saif-corp/myapp/api-test`. Create the stack under exactly that name, or the pipeline won't find it. The [service README](https://dev.azure.com/SAIFCorporation/SAIF/_git/pipeline-templates?path=/v2/deployments/terraform-pulumicloud/README.md&version=GBreleases/v3) covers the naming rules in full.

Don't use `terraform init -migrate-state`. Pulumi's [HCP Terraform migration steps](https://www.pulumi.com/docs/integrations/terraform/state-backend/#migrate-from-hcp-terraform-terraform-cloud) (fetched 2026-10-19) say HCP Terraform doesn't support it. Terraform 1.16.6 rejects a move from a `cloud` block to another backend with "Migrating state from HCP Terraform or Terraform Enterprise to another backend is not yet implemented", per [`meta_backend_migrate.go`](https://github.com/hashicorp/terraform/blob/v1.16.6/internal/command/meta_backend_migrate.go). Pointing the existing `cloud` block at `tf.pulumi.com` doesn't move state either. Terraform treats a change from one `cloud` block to another as an in-place change and migrates nothing, per [`meta_backend.go`](https://github.com/hashicorp/terraform/blob/v1.16.6/internal/command/meta_backend.go), so the new stack stays empty. Instead, pull the state from TFC and push it into a stack you create first.

Run every Terraform command in this step with Terraform 1.16.6, the SAIF Terraform standard. Pulumi's guide says to match your local version to the HCP Terraform workspace version before you pull. If the TFC workspace still runs an older version, raise its Terraform version setting to 1.16.6 before you freeze it.

1. Freeze the old runner so the state you copy stays current. Any TFC apply after the pull leaves the Pulumi Cloud copy stale.
    1. Disable the old Azure DevOps pipeline, and any other pipeline that can run Terraform against this workspace, so pushes to `main` no longer trigger it. This is the primary control.
    2. Wait for in-flight runs to finish. Confirm no run is queued or applying in the TFC workspace.
    3. Lock the TFC workspace from its Locking settings or with `POST /workspaces/:workspace_id/actions/lock`. Per HashiCorp's [workspace settings](https://developer.hashicorp.com/terraform/cloud-docs/workspaces/settings#locking) docs, a lock prevents all applies from the UI, CLI, API, and automation, and only the locking user can upload state. Plan-only runs still proceed, and workspace admins can force unlock, so treat the lock as a second guard behind the disabled pipeline.

    Keep the pipeline disabled and the workspace locked through cutover. Re-enable them only under [Rollback](#rollback).

2. Initialize against the old TFC backend and select the mapped workspace. Forge `cloud` blocks often select workspaces by `project` or `tags`, so the active workspace can belong to a different stack. Confirm that `terraform workspace show` prints the TFC workspace for this stack before you pull. Run `terraform login` first if you have not authenticated to TFC on this machine.

    ```bash
    terraform init
    terraform workspace select <tfc-workspace>
    terraform workspace show
    ```

3. Confirm that `terraform version` prints 1.16.6. The lock restricts state uploads, not reads, so `terraform state pull` still works. Pull the full state to a file outside the repo working tree, so nobody commits it, and confirm the backup lists your resources. The file holds plaintext state, including secrets.

    ```bash
    STATE_BACKUP="$HOME/tfc-state-backups/<project>_<stack>.tfstate"
    mkdir -p "$(dirname "$STATE_BACKUP")"
    terraform state pull > "$STATE_BACKUP"
    terraform state list -state="$STATE_BACKUP"
    ```

4. Create the Pulumi stack and pin it to local execution. Terraform can't create the stack for you, because `TF_WORKSPACE` only selects an existing workspace. HashiCorp's [`cloud` block reference](https://developer.hashicorp.com/terraform/language/block/terraform#environment-variables-for-the-cloud-block) (fetched 2026-10-19) says HCP Terraform won't create a workspace from that variable. Pulumi's [remote execution](https://www.pulumi.com/docs/integrations/terraform/remote-execution/) docs (fetched 2026-10-19) make `remote` the default execution mode for new stacks, and a Pulumi Cloud runner has none of the ESC credentials the pipeline injects. Run `pulumi login` first if you have not authenticated to Pulumi Cloud on this machine. Pulumi stack commands need a project file, so run them from a scratch directory, as the pipeline does.

    ```bash
    PROJECT="<project>"
    STACK="<stack>"
    STACK_REF="saif-corp/$PROJECT/$STACK"
    SCRATCH="$(mktemp -d)"
    printf 'name: %s\nruntime: yaml\n' "$PROJECT" > "$SCRATCH/Pulumi.yaml"
    (
      cd "$SCRATCH"
      pulumi stack init "$STACK_REF" || exit 1
      pulumi stack tag set terraform:execution-mode local -s "$STACK_REF"
      pulumi stack tag get terraform:execution-mode -s "$STACK_REF"
    )
    rm -rf "$SCRATCH"
    ```

    The last command must print `local`. If `pulumi stack init` reports that the stack already exists, stop. Someone else created it, and it may already hold state, so check it before you push anything.

5. Replace the TFC `cloud` block with one that points at Pulumi Cloud, and delete the local `.terraform` directory. Leave out the `workspaces` block. The pipeline selects the stack with `TF_WORKSPACE`, and so do you in the next substep.

    ```hcl
    terraform {
      cloud {
        hostname     = "tf.pulumi.com"
        organization = "saif-corp"
      }
    }
    ```

    Don't use the `backend "remote"` block with `workspaces { name = ... }` from Pulumi's guide. That form only knows the `default` workspace, and Terraform 1.16.6 rejects any other `TF_WORKSPACE` value with "workspaces not supported", per [`backend.go`](https://github.com/hashicorp/terraform/blob/v1.16.6/internal/backend/remote/backend.go). The pipeline always sets `TF_WORKSPACE`, so that block fails there.

    !!! note "How we verified this form"
        Pulumi's docs don't document a `cloud` block without `workspaces`. HashiCorp's reference says Terraform reads `TF_WORKSPACE` when `workspaces` is omitted. The Platform team probed this form against Pulumi Cloud on 2026-10-15 with Terraform v1.15.0 and v1.15.8. `TF_WORKSPACE=<project>_<stack>` selected the existing stack, and a missing stack failed with `Invalid workspace selection` and created nothing. Nobody has probed it on Terraform 1.16.6 yet.

6. Authenticate to `tf.pulumi.com` with `terraform login tf.pulumi.com` or by setting `TF_TOKEN_tf_pulumi_com`. Select the new stack with `TF_WORKSPACE`, run `terraform init`, and push the backup into the stack. Don't add `-force`. Without it, HashiCorp's [`state push`](https://developer.hashicorp.com/terraform/cli/commands/state/push) refuses a state with a differing lineage or a higher remote serial.

    ```bash
    terraform login tf.pulumi.com
    export TF_WORKSPACE="<project>_<stack>"
    terraform init
    terraform state push "$STATE_BACKUP"
    ```

    If `terraform init` fails with `Invalid workspace selection`, `TF_WORKSPACE` doesn't match the stack from substep 4. Fix the name rather than creating a second stack.

7. Run `terraform state list` against the new backend and confirm it lists the same resources as the backup. Don't run a local plan here. Your shell has no ESC credentials, so the first plan runs through the pipeline in Step 8.

!!! danger "Do not force the push"
    Pulumi's guide mentions `terraform state push -force` for lineage or serial errors. Don't use it in this migration. A lineage error usually means the target stack already holds different state. Stop and reconcile it first.

Pipelines on `SAIF/pipeline-templates` `releases/v3` already supply the `TF_TOKEN_tf_pulumi_com` credential for later CI runs. See [Forge v2 to v3](forge-v2-to-v3.md).

### Step 8: Verify with a plan

Run a plan through the new pipeline. The plan must show no unintended changes:

- **0 to destroy** and **0 to replace** for existing resources
- No new resources caused by the credential move
- The plan runs against the existing state, not a new empty stack

If the plan wants to create everything from scratch, the pipeline is pointed at a new, empty stack. Stop and see [State Safety](#state-safety).

If the run logs `Workspace does not exist - skipping Terraform setup`, the pipeline computed a different workspace name than the stack you created in Step 7. Compare the two and fix the deployment config rather than creating another stack.

### Step 9: Detach the TFC variable sets

Only after the plan is clean and the first apply succeeds, detach `okta-external-np`, `okta-external-prod`, `dynatrace-dev`, `dynatrace-prod`, and `aws-dns-<env>` from the old TFC workspace. Then delete the state backup from Step 7.

---

## State Safety

Config-name changes must not silently create a new empty stack or replace resources.

- **Workspace or stack renames**: Write down an explicit old-to-new mapping before you change any name. Move or import the existing state into the new stack before the first apply. Confirm the first plan runs against that state.
- **Resource address renames**: Add `moved` blocks for every address change. Confirm the plan shows moves, not destroy and create pairs.
- **Credential-only changes**: These should never change resource addresses. If a plan shows replaces after a credential-only change, the provider is reading the wrong tenant or account. Stop and check which saif environment file the pipeline environment uses.

---

## Rollback

Keep the old TFC workspace, its variable sets, and its credentials until cutover checks pass.

- **Input-only changes** (no state moved): Revert the branch to restore the previous provider wiring, variables, and pipeline. The TFC workspace still owns the state.
- **State already migrated**: Reconcile the TFC and new stack states, then pick one authoritative runner. Disable the other one before you apply again. If TFC stays authoritative, unlock the TFC workspace and re-enable the old pipeline only after you disable the new pipeline. Never run the old and new pipelines concurrently.

---

## Getting Help

If you hit an unexpected plan, a missing ESC value, or a stack that does not map cleanly to a `saif/<env>` environment, [open a Platform team support request](https://github.com/saif-corp/forge/issues/new) before you apply and include your `terraform plan` output.
