Skip to main content
skill CX Codex

pulumi-terraform-to-pulumi — Claude Code skill: migrate Terraform

Converts Terraform and OpenTofu projects to Pulumi: translates HCL into code and imports existing state into a Pulumi stack.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add pulumi/agent-skills --skill pulumi-terraform-to-pulumi -a claude-code
Open on GitHub

What pulumi-terraform-to-pulumi does

The skill walks a migration through in stages. First you and the agent settle the scope: where the Terraform sources live, where the Pulumi project should go, which language to target (TypeScript, Python, YAML), and whether you want state moved or only the source translated. The plan gets confirmed before anything runs.

Then the agent creates an empty project in the chosen directory with a stack, and pulls state with terraform state pull when there is no local .tfstate. That works against remote backends, Pulumi Cloud included. The terraform-migrate plugin, which installs itself when needed, produces a draft state file. /tmp/required-providers.json lists the providers and versions to add; install them through your language package manager rather than pulumi plugin install, which only downloads plugins. The draft is imported into the stack, and the source is rewritten until pulumi_preview shows an empty or near-empty diff.

A few constraints are firm. Do not run pulumi convert — it drops the state mapping, which is the whole reason the plugin exists. Create the project inside the checked-out repo, not under /workspace. If tofu refresh comes back unauthorized, that step is not skipped: you build a Pulumi ESC environment with the credentials, or the migration cannot proceed automatically. At the end the skill offers to link ESC to the stack and opens a pull request with the migrated code.

What it helps with

  • translate HCL infrastructure into Pulumi code
  • move Terraform state into a Pulumi stack without rewriting it by hand
  • pin the right Pulumi providers and versions for an existing project
  • drive the diff to zero with pulumi_preview after migration
  • open a pull request with the converted sources

Example prompts for the agent

  • Migrate the Terraform project in ./infra to Pulumi in TypeScript, state included
  • Convert OpenTofu to Pulumi in Python, sources are in ./tf
  • Translate this HCL to Pulumi and tell me which providers I need

How to install pulumi-terraform-to-pulumi

1Skills CLI (Vercel)

npx skills add pulumi/agent-skills --skill pulumi-terraform-to-pulumi -a claude-code

2Manually: put the files in place

~/.claude/skills/pulumi-terraform-to-pulumi/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/pulumi-terraform-to-pulumi/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about pulumi-terraform-to-pulumi

How do I install pulumi-terraform-to-pulumi in Claude?

Run npx skills add pulumi/agent-skills --skill pulumi-terraform-to-pulumi -a claude-code. The skill lands at ~/.claude/skills/pulumi-terraform-to-pulumi/SKILL.md.

What does pulumi-terraform-to-pulumi do?

It migrates a Terraform or OpenTofu project to Pulumi by translating HCL into your chosen language and importing the state into a stack. It follows a plan you confirm first.

How is this different from pulumi convert?

The skill deliberately avoids pulumi convert because it does not preserve state mapping. State is moved by the terraform-migrate plugin instead.

Source text

SKILL.md · Apache-2.0
---
name: pulumi-terraform-to-pulumi
description: Migrate Terraform/OpenTofu projects to Pulumi, including translating HCL source code and/or importing Terraform state into a Pulumi stack. Use when a user wants to convert Terraform to Pulumi, migrate from HCL, or import tfstate into Pulumi. Do NOT trigger for general Terraform-vs-Pulumi comparisons or questions about using both tools side-by-side.
---

# Migrating from Terraform to Pulumi

> **Critical constraints — read before acting:**
> - Do NOT run `pulumi convert` — use the terraform-migrate plugin instead, which preserves state mapping.
> - Do NOT run `pulumi package add terraform-module` — this is for a different workflow.
> - Do NOT create the Pulumi project under `/workspace` — create it inside the checked-out repo.
> - Replace `${terraform_dir}` and `${pulumi_dir}` below with the actual paths confirmed with the user.

First establish scope and plan the migration by working out with the user:

- where the Terraform sources are (`${terraform_dir}`)
- where the migrated Pulumi project lives (`${pulumi_dir}`)
- what is the target Pulumi language (such as TypeScript, Python, YAML)
- whether migration aims to setup Pulumi stack states, or only translate source code

Confirm the plan with the user before proceeding.

Create a new Pulumi project in `${pulumi_dir}` in the chosen language. Edit sources to be empty and not declare any
resources. Ensure a Pulumi stack exists.

You must run `pulumi_up` tool before proceeding to ensure initial stack state is written.

If no local `.tfstate` file exists in `${terraform_dir}`, the state may be in a remote backend (S3, Pulumi Cloud, Terraform Cloud, etc.). Pull it before proceeding:

    cd ${terraform_dir} && terraform state pull > terraform.tfstate

This works for all backends, including Pulumi Cloud. If `terraform` is not available, try `tofu state pull` instead.

Now produce a draft Pulumi state translation:

    pulumi plugin run terraform-migrate -- stack \
        --from ${terraform_dir} \
        --to ${pulumi_dir} \
        --out /tmp/pulumi-state.json \
        --plugins /tmp/required-providers.json

Do NOT install the plugin as it will auto-install as needed.

Sometimes terraform-migrate plugin fails because `tofu refresh` is not authorized. DO NOT skip this step. Work with the
user to find or build a Pulumi ESC environment that provides the necessary credentials so the command can succeed. If setting up an ESC environment is not feasible, inform the user that the migration cannot proceed automatically.

Read the generated `/tmp/required-providers.json` and install all these Pulumi providers into the new project,
respecting the suggested versions even if they downgrade an already installed provider. The file will contain records
such as `[{"name":"aws","version":"7.12.0"}]`.

Install providers as project dependencies using the language-specific package manager (NOT `pulumi plugin install`,
which only downloads plugins without adding dependencies):

    # TypeScript/JavaScript
    npm install @pulumi/[email protected]

    # Python
    pip install pulumi_aws==7.12.0

    # Go
    go get github.com/pulumi/pulumi-aws/sdk/[email protected]

    # C#
    dotnet add package Pulumi.Aws --version 7.12.0

Import the translated state draft (`/tmp/pulumi-state.json`) into the Pulumi stack:

    pulumi stack import --file /tmp/pulumi-state.json

Translate source code to match both the Terraform source and the translated state. Aim for exact match. You can consult
the state draft `/tmp/pulumi-state.json` for Pulumi resource types and names to use.

Iterate on fixing the source code until `pulumi_preview` tool confirms that there are no changes to make and the diff
is empty or almost empty. Provider diffs or diffs on tags may be OK.

Offer the user to link an ESC environment to the stack so that each Pulumi stack can seamlessly have access to the
provider credentials it needs.

When all looks good, create a Pull Request with the migrated source code.

© pulumi · Apache-2.0 · pulumi/agent-skills

Similar skills

Everything for DevOps and infrastructure →

From the same set13

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor