I have a resource created with a physical name usi...
# general
g
I have a resource created with a physical name using a random suffix. I had to manually create a replacement outside of Pulumi, and now I want to update the Pulumi state to adopt that resource. Is
pulumi state rename
+
pulumi refresh
what I want? It isn’t clear to me from the docs if
pulumi state rename
is for updating the physical name of the resource.
l
You might be able to make that work, but it's not what it's for. You want to import the appropriate resource. You could rename the existing resource, then import the new resource with the old Pulumi name. Remember that "physical" names are properties of the resource, whereas Pulumi names are the key of the resource in state. There is no requirement for the two values to be the same.
d
What's the recommend flow for importing a resource that already exists and has dependencies? Remove all dependencies from state then remove the resource itself, then finally import all resources (new resource + dependencies)?
l
Hmm. Depends on how comfortable you are editing state. If I was in that situation, I'd probably just edit the state and then
pulumi refresh
to get the real properties of the new resource.
If you wanted to avoid that and go with PulumiCLI the whole way, I think you'd have to do this: 1. Note the import IDs for all the old resource's dependencies (may require exporting and inspecting state). 2
pulumi state delete
the old resource and all of its dependencies. 3. Replace the code for the old resource with the code for the new resource. If you've used the old resource's name, this may be essentially a no-op. 4. Update the existing code for all the dependencies with the
import
opt. 5. Run
pulumi up
and resolve any sync errors. 6. Remove all the
import
opts.
d
Editing state is exporting the state, manually changing references and then importing it?
Also, Thanks!
l
Yes. If I was doing this, I'd just update the cloud identifiers (ARNs or IDs, whatever identifies the resource in the cloud) in the state. Then the same Pulumi state object is pointing at a different cloud object.
Highest risk, and zero opportunity for support from Pulumi if you muck it up. But also, lowest effort by far.
😄 1
d
Thanks a lot for the detailed answers!
👍 1