given that resource adoption is not implemented ye...
# general
f
given that resource adoption is not implemented yet (based on https://github.com/pulumi/pulumi/issues/1662) - is there a way to get existing AWS resource IDs by tags (much like terraform's data resource)?
s
So you have a few options here (I’m working on a plan for “proper” adoption at the moment, also): 1.
get
resources to populate their attributes. This can be done by ID:
Copy code
const vpc = aws.ec2.Vpc.get("my-vpc", id, {})
2. Use a data source - all of the Terraform data sources are mapped as functions with a
get
prefix:
Copy code
const publicHostedZoneId = (await aws.route53.getZone({           name: baseDomain,
})).id;
You can also convert the result into a pulumi.output instead of awaiting it if necessary
Using the data source approach gives you the same options as Terraform for how to filter
f
that first example is exactly what i was looking for
s
If you are just getting something by ID, 1 is better.
👍 1
f
i just could not find it in the docs - likely passed it over
s
Did you say you need to look things up by Tag value though?
f
ideally, ya - that would make it dynamic
vpc is simple enough to just do a
get
- but subnets, security_groups would be kind of a pain
s
Yeah - so for those you can use the data source method:
Copy code
const amiId = (await aws.getAmi({
        owners: ["self"],
        mostRecent: true,
        filters: [{
            name: "name",
            values: ["some-ami-*"],
        }],
    })).id;
Note that for getting by ID there is a static method on the resource type, whereas the data sources are mapped into the resource namespace
f
so can I just replace
Ami
with any other resource type?
i dont see a
getVpc
for example in the reference docs for
aws
s
So AMI is a weird case, and I think it might be mapped poorly (cc @white-balloon-205) - it really should be
aws.ec2.getAmi
) - most get functions are in the module for their namespace
f
ah ok, i scrolled past the modules section
thanks!
s
No worries - let me know if you’re still stuck following this