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 从公开仓库中收录这些内容。

举报或申请下架