Pulumi Terraform To Pulumi

pulumi/agent-skills/migration/skills/pulumi-terraform-to-pulumi

作者 pulumi900eacf4444f無授權條款70 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫昨天更新

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.

僅含說明DevOps & Cloud
AI 產生的概覽

透過轉換 HCL 原始碼並將 Terraform 狀態匯入 Pulumi 堆疊,把 Terraform 或 OpenTofu 專案遷移到 Pulumi。

功能
此技能引導代理將 Terraform/OpenTofu 專案轉換為指定語言的 Pulumi 專案。它會建立空的 Pulumi 專案與堆疊,在沒有本機狀態檔案時拉取遠端 Terraform 狀態,執行 terraform-migrate 外掛產生 Pulumi 狀態轉換草稿,安裝所需的 Pulumi 提供者,並將轉換後的狀態匯入堆疊。接著它會翻譯原始碼,使其與 Terraform 原始碼及轉換後的狀態一致,反覆迭代直到預覽顯示差異為空或幾乎為空,最後建立包含遷移程式碼的提取要求。
適用情境
適用於使用者想將 Terraform 或 OpenTofu HCL 轉換為 Pulumi、從 HCL 遷移,或將 tfstate 匯入 Pulumi 堆疊的情況。不適用於一般 Terraform 與 Pulumi 的比較,或關於同時使用這兩種工具的問題。
執行需求
需要 Pulumi CLI 與 terraform-migrate 外掛(會自動安裝)、pulumi_up 和 pulumi_preview 工具,以及用於拉取狀態的 terraform 或 tofu CLI。重新整理狀態需要提供者認證,可能透過 Pulumi ESC 環境提供,還需要網路存取與語言相關的套件管理器(npm、pip、go 或 dotnet)。此技能不含指令碼,僅為說明文件。

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/JavaScriptnpm install @pulumi/[email protected]
# Pythonpip install pulumi_aws==7.12.0
# Gogo 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/agent-skills位於migration/skills/pulumi-terraform-to-pulumi提交900eacf

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架