https://pulumi.com logo
Title
f

fierce-ability-58936

10/25/2022, 8:45 PM
Is there a way to easily import resources created outside of Pulumi / code and then codified? Currently it's too annoying to try to figure out the right parent and import ID for every resource, whereas those should be already in the code. I've tried some
pulumi refresh --import-pending-creates
magic but it didn't work out (and frankly it looks like it's meant to be something else?). Ideally, there should be something like "pulumi up --import target"
l

little-cartoon-10569

10/25/2022, 8:49 PM
The options are to write the code yourself and add the
import
opt, or have Pulumi write the code for you using
pulumi import
. You never need to figure out parents, since that's just a cosmetic thing (unless you're inheriting opts / providers). Import IDs are calculated for you if you use
pulumi import
There's no way to specify an import id on the command line. It wouldn't be easy to get working in a project with hundreds of resources...
f

fierce-ability-58936

10/25/2022, 8:53 PM
The import opt will work! However, it's not always possible to modify the code, like in my case 🙂 Maybe I'm doing something unusual - I manage Route53 records with Pulumi, and the zone config is expressed in an YAML file (a file per zone actually), which is then read and interpreted by Pulumi. This way, I can write zone files in the most convenient and easiest way.
Does it sound like a good idea to be able to do something like: 1. User runs
pulumi up
and looks at the resources that are going to be created 2. The user knows the resources are already there and wants to just import them 3. They interactively mark them as "import only" 4. Or if they know in advance they want to import all, they can provide a regex for urns (to allow partial match) or several regexes via a flag. ?
Oh, this world is so small, you're from Wellington too! 🙂
l

little-cartoon-10569

10/25/2022, 9:41 PM
Napier now, actually 🙂
I don't know of a way to import resources using static code. You need to edit the code to get importing working. I suppose if you were really confident, you could export the stack, update it, and import it again.. but I'm not recommending that...
f

fierce-ability-58936

10/25/2022, 9:50 PM
I've actually used https://www.pulumi.com/docs/guides/adopting/import/#bulk-import-operations before, but it's not the most user-friendly. aws route53 list-resource-record-sets | some jq magic && pulumi import -f file.json But it's not the most user-friendly way. I wouldn't export/import the stack json, it's a rabbit hole 🙂