Moving Pulumi resources from one project to another can be a complex process. If you've ever found yourself navigating this challenge, worry not; I've compiled a step-by-step guide that can serve as a lifeline for anyone in a similar situation.
Target the Pulumi Project:
Begin by selecting the Pulumi project that you wish to export resources from. To do this, use the following command:
pulumi stack select
Export Resources:
Next, export all the resources from your selected stack into a JSON file. Use the following command:
pulumi stack export --file test.json
Normalize the Exported File:
To ensure a cleaner and more manageable format, copy the provided PowerShell script into your project and run it.
Note that you should replace 'test.json' in line 1 with the actual filename used for export:
Run the above PowerShell script
./normalize-export.ps1
Review and Customize:
After running the script, examine the 'export.json-normalized.json' file. Here, you can remove any resources that you do not intend to import into the new project.
Import Resources into the New Project:
In your new project, select the stack where you want to import the resources. Repeat the entire process for each stack you need to import by using the following command:
pulumi import -f test.json-normalized.json
Verify Changes:
Once you've completed the import process, execute a 'pulumi preview' in your new project. This should indicate minimal to no changes.
Cleanup the Old Project:
To finalize the migration, remove the resource state from the old project. You can use the provided script, ensuring that you set the project name and stack name within the file.
These values are crucial for building pulumi URNs. The script only outputs the necessary commands, but you can modify it to execute them for you.
That's it! Hopefully, this guide will save you valuable time during your resource migration process.