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.

Skills เพิ่มเติมจาก pulumi

package-usage
pulumi
ติดตามว่าสแต็กใดในองค์กร Pulumi ที่ใช้แพ็กเกจเฉพาะและในเวอร์ชันใด ใช้สำหรับการตรวจสอบข้ามสแต็ก ระบุเวอร์ชันที่ล้าสมัยหรือไม่ได้รับการดูแล...
official
pulumi-automation-api
pulumi
การจัดเรียงการทำงานของโครงสร้างพื้นฐาน Pulumi แบบโปรแกรมเมติกข้ามหลายสแต็กและแอปพลิเคชัน รองรับทั้งสถาปัตยกรรมแหล่งที่มาในเครื่อง (โปรเจกต์ Pulumi ที่มีอยู่) และแหล่งที่มาแบบอินไลน์ (โปรแกรมที่ฝังตัว) ทำให้สามารถปรับใช้รูปแบบการปรับใช้ได้อย่างยืดหยุ่นตั้งแต่สถานการณ์ง่ายไปจนถึงซับซ้อนหลายสแต็ก จัดการการจัดเรียงหลายสแต็กด้วยลำดับการพึ่งพา การปรับใช้แบบอิสระแบบขนาน และการส่งผ่านเอาต์พุตข้ามสแต็กสำหรับการจัดเตรียมโครงสร้างพื้นฐานที่ประสานงานกัน ให้การทำงานแบบโปรแกรมเมติก...
official
pulumi-best-practices
pulumi
แนวทางปฏิบัติที่ดีที่สุดสำหรับการเขียนโค้ดโครงสร้างพื้นฐาน Pulumi ที่เชื่อถือได้และบำรุงรักษาได้ หลีกเลี่ยงการสร้างทรัพยากรภายใน callback ของ apply() ส่งผ่านอ็อบเจกต์ Output โดยตรงเป็นอินพุตเพื่อรักษาการติดตามการพึ่งพาและการมองเห็นในตัวอย่าง ใช้คลาส ComponentResource เพื่อจัดกลุ่มทรัพยากรที่เกี่ยวข้องเป็นหน่วยตรรกะที่นำกลับมาใช้ใหม่ได้พร้อมลำดับชั้น parent-child ที่เหมาะสมผ่าน parent: this เข้ารหัสความลับตั้งแต่เริ่มต้นด้วยแฟล็ก --secret หรือ config.requireSecret() เพื่อป้องกันการรั่วไหลของข้อมูลประจำตัวในไฟล์สถานะ...
official
pulumi-component
pulumi
ส่วนประกอบโครงสร้างพื้นฐานที่นำกลับมาใช้ใหม่ได้พร้อมรองรับหลายภาษา ค่าเริ่มต้นที่เหมาะสม และรูปแบบการประกอบ ต้องมีองค์ประกอบหลักสี่ประการ: ขยาย ComponentResource, ยอมรับพารามิเตอร์มาตรฐาน, ตั้งค่า parent: this บน child ทั้งหมด, และเรียก registerOutputs() ที่ส่วนท้ายของ constructor อินเทอร์เฟซ Args ต้องใช้ wrapper Input<T>, หลีกเลี่ยง union types และฟังก์ชัน, และรักษาโครงสร้างให้เรียบเพื่อรองรับการสร้าง SDK หลายภาษา เปิดเผยเฉพาะ output ที่จำเป็นเป็น public properties; ซ่อน...
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