m

    microscopic-dress-1605

    8 months ago
    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

    8 months ago
    import takes a
    --parent <urn>
    option, pass the component resources urn to that when importing.
    l

    limited-rainbow-51650

    8 months ago
    How deeply can this be nested?
    e

    echoing-dinner-19531

    8 months ago
    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

    8 months ago
    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

    8 months ago
    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

    8 months ago
    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

    8 months ago
    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

    7 months ago
    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
    {
      "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

    7 months ago
    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

    7 months ago
    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

    7 months ago
    Sorry I don't have any code about to do this but that logic makes sense
    a

    ambitious-mouse-72396

    7 months ago
    Just to update, initial testing has this working well. Thanks.