pulumi-terraform-to-pulumi

作者: pulumi

將 Terraform/OpenTofu 專案遷移至 Pulumi,包括轉譯 HCL 原始碼及/或將 Terraform 狀態匯入 Pulumi 堆疊。當使用者…

npx skills add https://github.com/pulumi/agent-skills --skill pulumi-terraform-to-pulumi

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/aws@7.12.0

# Python
pip install pulumi_aws==7.12.0

# Go
go get github.com/pulumi/pulumi-aws/sdk/v7@v7.12.0

# 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 的更多技能

package-usage
pulumi
追蹤 Pulumi 組織中各堆疊使用特定套件及其版本的情況。用於跨堆疊審計,識別過時或未維護的…
official
pulumi-automation-api
pulumi
跨多個堆疊與應用程式的 Pulumi 基礎設施操作之程式化編排。支援本地來源(現有 Pulumi 專案)與內嵌來源(嵌入式程式)架構,實現從簡單到複雜多堆疊場景的靈活部署模式。處理具相依性排序的多堆疊編排、平行獨立部署,以及跨堆疊輸出傳遞,以達成協調的基礎設施佈建。提供程式化...
official
pulumi-best-practices
pulumi
撰寫可靠、可維護的 Pulumi 基礎設施程式碼的全面最佳實踐。避免在 apply() 回呼中建立資源;直接將 Output 物件作為輸入傳遞,以保留依賴追蹤與預覽可見性。使用 ComponentResource 類別將相關資源分組為可重複使用的邏輯單元,並透過 parent: this 建立正確的父子層級。從一開始就使用 --secret 標誌或 config.requireSecret() 加密機密資訊,以防止憑證在狀態檔案中洩漏...
official
pulumi-component
pulumi
可重複使用的基礎架構元件,支援多語言、合理的預設值與組合模式。需具備四個核心要素:繼承 ComponentResource、接受標準參數、為所有子資源設定 parent: this,並在建構函式結尾呼叫 registerOutputs()。Args 介面必須使用 Input<T> 包裝器,避免聯合型別與函式,並保持結構扁平以支援多語言 SDK 生成。僅將必要的輸出暴露為公開屬性;隱藏...
official
pulumi-debug-failed-operation
pulumi
調試失敗的 Pulumi 更新或預覽:讀取 Pulumi 已記錄的失敗資訊,找出原因並修復。當使用者要求…時載入此技能。
official
pulumi-esc
pulumi
集中式機密、配置及動態憑證管理,適用於Pulumi基礎設施與應用程式。支援透過匯入與分層進行環境組合,並保留 environmentVariables 、 pulumiConfig 及 files 的保留鍵。透過OIDC為AWS、Azure及GCP產生短期憑證;可整合AWS Secrets Manager、Azure Key Vault、HashiCorp Vault及1Password。核心CLI指令包含 pulumi env init 、 pulumi env edit 、 pulumi env open (顯示...
official
pulumi-neo-handoff
pulumi
將當前線程以單向傳輸方式移交給新的 Pulumi Neo 任務。當用戶明確要求移交、發送、轉移或繼續當前…時使用。
official
pulumi-overview
pulumi
使用此技能處理任何建立、修改、檢查或銷毀雲端基礎設施或SaaS配置的任務,範圍從一次性CLI操作到完整…
official