Hello, I’m trying to import a resource that is ins...
# general
Hello, I’m trying to import a resource that is inside a
using the pulumi cli. When I execute
pulumi import pulumi-resource-id cloud-provider-resource-id
the resource is successfully imported. However, the resource is then a top-level resource and not a chilled of the Custom Resource. Thank you for your help!
import takes a
--parent <urn>
option, pass the component resources urn to that when importing.
👌🏼 1
How deeply can this be nested?
Arbitrarily pretty much. URNs aren't a full path they only include the information about their parent type which is why https://www.pulumi.com/docs/intro/concepts/resources/#urns has some docs about making sure names are globally unique.
Ah, so even if components are nested, you only point to the direct parent of the resource you want to import?
But what if the parent does not yet exist? Is there a way to create a new parent?
Thank you @echoing-dinner-19531 for your help!!!
But what if the parent does not yet exist? Is there a way to create a new parent?
I'm not sure, I feel like we should have an answer for importing a component resource but I don't think there's anyway to do it right now except manually editing the pulumi state file. It's probably worth raising an issue at https://github.com/pulumi/pulumi/issues/ explaining the component resource your trying to import
Ok. In the mean time I’ve solved it by using the
directive in the code. Worked as a charm.
I just hit this same issue. Can you elaborate on on how
is calculated or can it always be 1 when I add a component directly to the state
Copy code
  "urn": "urn:pulumi:mystack::muyproject::dennis:modules:backend-analytics::backend-analytics",
  "custom": false,
  "type": "dennis:modules:backend-analytics",
  "parent": "urn:pulumi:mystack::myproject::pulumi:pulumi:Stack::mystack",
  "sequenceNumber": 1
Yes new resources should start with a sequence number of 1.
The sequence number is incremented everytime we replace the resource (i.e. delete it and re-create it)
Thank you. I’m gonna give this a shot. No chance you have a code snippet example of modifying the state lying around? If not my plan is something like: 1. pulumi state export 2. load that in python with json.load 3. iterate over deployment.resources to find the stack urn 4. add my component to the state, using the stack urn as the parent 5. dump back out to file 6. pulumi state import Does this logic make sense?
Sorry I don't have any code about to do this but that logic makes sense
Just to update, initial testing has this working well. Thanks.
🙌 1