fresh-wire-95028
10/19/2021, 8:32 PMPromise
as an input
in pulumi?
Example I want to use:
get privateSubnetIds(): Promise<pulumi.Output<string>[]>;
from a `Vpc`:
const vpc = new awsx.ec2.Vpc(..., {
...
});
in a `NetworkAssociation`:
const networkAssociation = new aws.ec2clientvpn.NetworkAssociation(`...`, {
subnetId: vpc.privateSubnetIds[0],
});
little-cartoon-10569
10/19/2021, 8:33 PMfresh-wire-95028
10/19/2021, 8:41 PMprivateSubnetIds[0]
as an input in a clientvpn
NetworkAssociation
little-cartoon-10569
10/19/2021, 8:47 PMapply()
or then()
, so let's do that.subnetId
property can take an Input<string>
, so we want a Promise<string>
or Output<string>
there.vpc.privateSubnetIds.then(subnetIds => subnetIds[0].id)
returns a promise wrapping a string id.pulumi.output(vpc.privateSubnetIds)[0].id
maybe? Haven't tried that.pulumi.output(vpc.privateSubnetIds[0]).id
. I think it looks better than the then()
version above.fresh-wire-95028
10/19/2021, 10:02 PMconst defaultPrivateSubnetId = pulumi
.output(vpc.privateSubnetIds)
.apply((ids) => ids[0]);
const defaultPrivateSubnetCidrBlock = pulumi
.output(vpc.privateSubnets)
.apply((subnet) => subnet[0].subnet.cidrBlock);
const networkAssociation = new aws.ec2clientvpn.NetworkAssociation(
`${name}-network-association`,
{
clientVpnEndpointId: endpoint.id,
subnetId: defaultPrivateSubnetId,
},
);
// allows the following subnet groups to access these subnets
const authorizationRule = new aws.ec2clientvpn.AuthorizationRule(
`${name}-authorization-rule`,
{
clientVpnEndpointId: endpoint.id,
targetNetworkCidr: defaultPrivateSubnetCidrBlock,
authorizeAllGroups: true,
},
);
little-cartoon-10569
10/19/2021, 10:39 PMconst defaultPrivateSubnetId = pulumi.output(vpc.privateSubnetIds).apply((ids) => ids[0]);
If you do it inline (i.e., eliminate the defaultPrivateSubnetId
variable), then I think that Pulumi's output promotion will handle it for you.
subnetId: pulumi.output(vpc.privateSubnetIds)[0]
Hopefully awsx will return an output version of all those promises, at some point in the future.fresh-wire-95028
10/20/2021, 7:09 PM