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

microscopic-dress-1605

01/13/2022, 4:41 PM
Hello, I’m trying to import a resource that is inside a
CustomResource
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!
e

echoing-dinner-19531

01/13/2022, 4:52 PM
import takes a
--parent <urn>
option, pass the component resources urn to that when importing.
👌🏼 1
l

limited-rainbow-51650

01/13/2022, 4:53 PM
How deeply can this be nested?
e

echoing-dinner-19531

01/13/2022, 4:56 PM
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.
l

limited-rainbow-51650

01/13/2022, 5:00 PM
Ah, so even if components are nested, you only point to the direct parent of the resource you want to import?
m

microscopic-dress-1605

01/13/2022, 5:27 PM
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!!!
e

echoing-dinner-19531

01/13/2022, 5:45 PM
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
m

microscopic-dress-1605

01/13/2022, 6:41 PM
Ok. In the mean time I’ve solved it by using the
import
directive in the code. Worked as a charm.
a

ambitious-mouse-72396

02/23/2022, 8:32 PM
I just hit this same issue. Can you elaborate on on how
sequence
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
}
e

echoing-dinner-19531

02/23/2022, 8:33 PM
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)
a

ambitious-mouse-72396

02/23/2022, 9:04 PM
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?
e

echoing-dinner-19531

02/23/2022, 9:16 PM
Sorry I don't have any code about to do this but that logic makes sense
a

ambitious-mouse-72396

02/24/2022, 1:37 PM
Just to update, initial testing has this working well. Thanks.
🙌 1
131 Views