`ec2.Vpc.getSubnets` returns a `Promise<ec2.Sub...
# typescript
m
ec2.Vpc.getSubnets
returns a
Promise<ec2.Subnet[]>
as opposed to an
Output<ec2.Subnet>[]
. Is this safe to use as an arg (Input) to a subsequent resource where I need to provide a subnet id?
b
we have the new
ec2.Vpc.getSubnetsOutput
which might be more helpful in this scenario
m
Ah, doesn't look like it's on my version awsx.Vpc (sorry should've mentioned this is awsx)
b
oh, sorry yes it's not in there yet
and no, you can't pass a promise to an Output, you'll need to await it and then build an output, which won't be fun
m
yeah sounds like bad things will occur 😅
Copy code
vpc.id.apply(() => vpc.publicSubnets)
wrap in a relateed output to maintain dependency data, return promise to subnets which should resolve some time after vpc.id
(in my head)
r
What @magnificent-lifeguard-15082 suggested worked as a charm ❤️
Copy code
const publicSubnetsIds = vpc.id.apply(async () => vpc.getSubnetsIds("public"));
and then I use it like this:
Copy code
const alb = new aws.lb.LoadBalancer(`${name}-alb`, {
      internal: false,
      loadBalancerType: "application",
      securityGroups: [albSecGroup.id],
      subnets: publicSubnetsIds.apply((ids) => ids),
    });
Thanks a bunch, @magnificent-lifeguard-15082!
❤️ 1
e
publicSubnetsIds.apply((ids) => ids),
is the same as just
publicSubnetsIds
👍 1
r
hmhmh, this confuses me my IDEA says something else:
b
does this not work?
Copy code
const alb = new aws.lb.LoadBalancer(`${name}-alb`, {
      internal: false,
      loadBalancerType: "application",
      securityGroups: [albSecGroup.id],
      subnets: publicSubnetsIds
    });
r
Oh, got it - it does 😄
thanks!