Hi I’m splitting a stack in two… global resources ...
# general
a
Hi I’m splitting a stack in two… global resources in 1 stack, other resources in two other stacks. Is there an easy way to migrate state from a stack to another without breaking and re-creating everything? ( @brash-army-97932 for visibility )
s
I don't believe so. There's a hacky workaround involving
pulumi stack export
and
pulumi stack import
, but it's not supported.
a
Is it feasible to modify it manually?
s
Yes, that's the workaround. I need to write the blog post about it. 🙂 The general process is (working from memory): 1. Export the stack to a JSON file. 2. Modify the JSON file to include only the resources you want in the new stack. 3. Remove the resources from the state of the original stack (this won't affect the resources, just Pulumi's awareness/management of them). 4. Import the modified JSON into a new stack. 5. Update your code (for both stacks) so that
pulumi up
shows no changes.
a
Makes sense, there’s only like logical label => physical resource, no hashes or checksums of parameters or stuff like that?
s
I don't think so, but you will need to do some search-replace for URNs in step 2 (the stack name is in the URN).
a
Ok sounds doable, thanks!
m
I just did this, and it took quite a while. I was manually importing and deleting resources while separating the code.
a
It’s probably going to be a bit troublesome especially because we have 2k resources in the stack but deleting and recreating everything is not an option lol it’s production infra
We’ll do plenty of backups and test everything thoroughly
and ultimately hope for the best!
m
good luck!