I have some resources that were setup manually tha...
# general
a
I have some resources that were setup manually that I would like to import into a new stack as resources inside of a custom component resource. Is that something that can be managed through
pulumi import
with something like the multiple resource importing as described here? https://www.pulumi.com/blog/pulumi-import-generate-iac-for-existing-cloud-resources/#importing-multiple-resources
w
Yes. The
pulumi import
will do two things, it will bring the resources under Pulumi management and it will generate scaffolding code you can use to mange the resources’ configuration going forward.
a
Hi @witty-candle-66007. Apologies for the late reply, but can you point me in the direction for docs on how I would need to structure the import?
w
The command is documented here: https://www.pulumi.com/docs/reference/cli/pulumi_import/ And the specific values to use are described in the "import" section for a given resource API documentation. For example, in the S3 resource docs, you'll see this: https://www.pulumi.com/docs/reference/pkg/aws/s3/bucket/#import
a
For context, this is an example of the resources in the component resource
Copy code
pulumi:pulumi:Stack                                             cockroach-cockroach.dev
    │  URN: urn:pulumi:cockroach.dev::cockroach::pulumi:pulumi:Stack::cockroach-cockroach.dev
    ├─ es:ec2:PersistentEc2InstanceGroup                            cockroach
    │  │  URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup::cockroach
    │  ├─ my:ec2:PersistentEc2Instance                      cockroach-2
    │  │  │  URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance::cockroach-2
    │  │  ├─ aws:ebs/volume:Volume                                  cockroach-2-data
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ebs/volume:Volume::cockroach-2-data
    │  │  ├─ aws:ec2/instance:Instance                              cockroach-2
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/instance:Instance::cockroach-2
    │  │  ├─ aws:cloudwatch/metricAlarm:MetricAlarm                 cockroach-2-recovery
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:cloudwatch/metricAlarm:MetricAlarm::cockroach-2-recovery
    │  │  ├─ aws:ec2/volumeAttachment:VolumeAttachment              cockroach-2-data-attach
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/volumeAttachment:VolumeAttachment::cockroach-2-data-attach
    │  │  ├─ aws:route53/record:Record                              cockroach-2-dns
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-2-dns
    │  │  └─ aws:route53/record:Record                              cockroach-2-rdns
    │  │        URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-2-rdns
    │  ├─ my:ec2:PersistentEc2Instance                      cockroach-1
    │  │  │  URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance::cockroach-1
    │  │  ├─ aws:ebs/volume:Volume                                  cockroach-1-data
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ebs/volume:Volume::cockroach-1-data
    │  │  ├─ aws:ec2/instance:Instance                              cockroach-1
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/instance:Instance::cockroach-1
    │  │  ├─ aws:cloudwatch/metricAlarm:MetricAlarm                 cockroach-1-recovery
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:cloudwatch/metricAlarm:MetricAlarm::cockroach-1-recovery
    │  │  ├─ aws:ec2/volumeAttachment:VolumeAttachment              cockroach-1-data-attach
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/volumeAttachment:VolumeAttachment::cockroach-1-data-attach
    │  │  ├─ aws:route53/record:Record                              cockroach-1-dns
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-1-dns
    │  │  └─ aws:route53/record:Record                              cockroach-1-rdns
    │  │        URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-1-rdns
    │  ├─ my:ec2:PersistentEc2Instance                      cockroach-0
    │  │  │  URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance::cockroach-0
    │  │  ├─ aws:ebs/volume:Volume                                  cockroach-0-data
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ebs/volume:Volume::cockroach-0-data
    │  │  ├─ aws:ec2/instance:Instance                              cockroach-0
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/instance:Instance::cockroach-0
    │  │  ├─ aws:cloudwatch/metricAlarm:MetricAlarm                 cockroach-0-recovery
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:cloudwatch/metricAlarm:MetricAlarm::cockroach-0-recovery
    │  │  ├─ aws:ec2/volumeAttachment:VolumeAttachment              cockroach-0-data-attach
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:ec2/volumeAttachment:VolumeAttachment::cockroach-0-data-attach
    │  │  ├─ aws:route53/record:Record                              cockroach-0-dns
    │  │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-0-dns
    │  │  └─ aws:route53/record:Record                              cockroach-0-rdns
    │  │        URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$my:ec2:PersistentEc2Instance$aws:route53/record:Record::cockroach-0-rdns
    │  ├─ aws:lb/targetGroupAttachment:TargetGroupAttachment        cockroach-1
    │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$aws:lb/targetGroupAttachment:TargetGroupAttachment::cockroach-1
    │  ├─ aws:lb/targetGroupAttachment:TargetGroupAttachment        cockroach-2
    │  │     URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$aws:lb/targetGroupAttachment:TargetGroupAttachment::cockroach-2
    │  └─ aws:lb/targetGroupAttachment:TargetGroupAttachment        cockroach-0
    │        URN: urn:pulumi:cockroach.dev::cockroach::es:ec2:PersistentEc2InstanceGroup$aws:lb/targetGroupAttachment:TargetGroupAttachment::cockroach-0
I have imported stock resources fine.
w
Oh - I didn't pick up on the "component resource" part of the question. Sorry.
a
I think I see how it may work based on the json in the cli docs
w
I'm going to ask the team for any pointers as well.
a
I'm going to give that a shot. I mostly care about getting the ec2 instances into state.
w
Answer from engineering:
Copy code
So if the user defines the component resource in their code with no children, runs an update to create the component, they can then use pulumi import on the existing resources and specify the URN of the component as the parent
a
@witty-candle-66007 I just wanted to follow up and give you a huge thanks. That worked and saved me a huge amount of effort.
w
Glad to hear. Thanks