Is it pointless to use any of the resource-getting...
# typescript
l
Is it pointless to use any of the resource-getting functions in a resource constructor? I want to call
awsx.ec2.Vpc.fromExistingIds
to load a Vpc created elsewhere so that I can create a new route on one of its subnets. But
awsx.ec2.Vpc#privateSubnets
is
async
, and typescript doesn't allow use of
await
in constructors. I assume that I have to use an async function called after my constructor?
g
Two ways to do it: • Make a constructor that takes the responses, not the ids, and a static async method. The boring way • Wrap the responses in
pulumi.output
and treat them as any pulumi resource, manipulating using
.apply(...)
l
Thanks. I didn't know you could wrap a Promise with
pulumi.output
and use apply in the normal way, that's useful. I do the opposite in my tests all the time, I should have guessed!
I think I'll go with your first option though: a little rework allows me to pass the Vpc in from the project, and later I'll be able to switch to using StackReferences, like I should. (Can't do that yet because of our chosen backend solution.)
g
I personally prefer to have all my inputs types as
pulumi.Input<something>
and then use it with
pulumi.output
, this my functions and constructors accepts resource outputs, promises and raw values at any time
👍 1
l
Good idea. Makes it slightly more verbose in the unit tests: we put 99% of code in ComponentResources and unit test them, so the overhead is noticeable. But it's worth it, I think. Certainly worth doing for new classes.