https://pulumi.com logo
f

fancy-magazine-29876

01/11/2019, 8:25 PM
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

stocky-spoon-28903

01/11/2019, 8:42 PM
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

fancy-magazine-29876

01/11/2019, 8:43 PM
that first example is exactly what i was looking for
s

stocky-spoon-28903

01/11/2019, 8:43 PM
If you are just getting something by ID, 1 is better.
👍 1
f

fancy-magazine-29876

01/11/2019, 8:43 PM
i just could not find it in the docs - likely passed it over
s

stocky-spoon-28903

01/11/2019, 8:44 PM
Did you say you need to look things up by Tag value though?
f

fancy-magazine-29876

01/11/2019, 8:44 PM
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

stocky-spoon-28903

01/11/2019, 8:47 PM
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

fancy-magazine-29876

01/11/2019, 8:49 PM
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

stocky-spoon-28903

01/11/2019, 8:51 PM
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

fancy-magazine-29876

01/11/2019, 8:52 PM
ah ok, i scrolled past the modules section
thanks!
s

stocky-spoon-28903

01/11/2019, 9:05 PM
No worries - let me know if you’re still stuck following this