https://pulumi.com logo
#general
Title
# general
b

better-shampoo-48884

05/19/2021, 6:52 AM
So.. I've spent the past few weeks refactoring my pulumi code to ComponentResource spec - and I've got one outstanding question before I embark on a new world of pain.. Right now I have one primary ComponentResource for each resource type, with the provider specific resource directly underneath. I'm planning on making another change to create a new provider-type specific ComponentResource. Currently i have ComponentResource "network" which handles virtual networks, subnets, security groups, etc. What I want to do is introduce a Component Resource inside of the "network" one which is called "azure-net" so that the "network" resource can be cloud-agnostic (all network resources take pretty much the same configuration regardless of provider - so I'll be leveraging that with sensible defaults and overrides). My question is really this: My URNs will likely change when I perform the operation, and I'm creating ~40xN resources (where N is number of datacenters/regions it should span) for each stack - is there a sensible way of reimporting created resources? Current URN:
Copy code
urn:pulumi:mystack::myproject::purpose:components:provider$purpose:components:group$purpose:components:k8s$azure-native:containerservice:ManagedCluster$random:index/randomUuid:RandomUuid::mystack-cluster-k8s-location-diskcrypto-to-kv-cert-RA
I'm guessing the
:components:k8s$azure-native:
bit is what's going to change. Initial thought: export the stack + search and replace + reimport stack? Any other ideas? Doing
pulumi import
on each one is.. just not going to work, besides taking a huge amount of time, it will just be really really really tricky to ensure I have the right URN specified for each resource.
l

little-cartoon-10569

05/19/2021, 8:37 PM
You can use the alias opt, so that each resource has both its original URN and its new one.
To do the same thing without aliases is more complex and probably not worth it in a big reworking like this, but I've used this approach with one or two resources at a time and it's a clean and repeatable process. 1. Freeze all changes except for this! It's a multistep process. Backup your state (
pulumi stack output --file x.json
). 2. Comment / flag out all the resources that will be changing, so that you create all their parents correctly without importing anything. 3. Comment / flag out the original resources and remove them from state (
pulumi state delete
). 4. Run
pulumi import --parent ...
to import the resources to the correct place. 5. Comment / flag in the new code for the resources, making it look like the code that Pulumi generated. 6. Tidy up old commented / flagged-out code. 7.
pulumi preview
to check everything in state matches.
2 Views