sparse-intern-71089
06/05/2019, 9:16 PMwhite-balloon-205
Promise<string[]> like this:
async function getSubnetIds(vpcId: string): Promise<string[]> {
const res = await aws.ec2.getSubnetIds({ vpcId: "123" });
return res.ids;
}
But then if you want to loop over these in your code, you'll need to write that loop inside an async function or a then callback on the promise.
For stack exports - the code you shared above works for me as written - and produces:
+ subnetIds: {
+ id : "vpc-c93b06ae"
+ ids : [
+ [0]: "subnet-00412149"
+ [1]: "subnet-fd19eaa6"
+ [2]: "subnet-ba4009dd"
+ [3]: "subnet-8a599ba1"
]
+ vpcId: "vpc-c93b06ae"
}proud-alarm-92546
06/05/2019, 9:40 PMvpcId is from config so there's a bit of complex that it picks up along the wayproud-alarm-92546
06/05/2019, 9:44 PM"vpc-1234" though.proud-alarm-92546
06/05/2019, 9:49 PMif ( config.createVpc == false ) {
export const ccsubnetIds = pulumi.concat(aws.ec2.getSubnetIds({ vpcId: vpcId, }));
}
can't do the export from inside an if...... that's where the error TS1184: Modifiers cannot appear here comes in.proud-alarm-92546
06/05/2019, 10:16 PMasync function getSubnetIds(vpcId: string): Promise<string[]> {
const res = await aws.ec2.getSubnetIds({ vpcId: vpcId });
return res.ids;
};
export const subnetIds = getSubnetIds(config.vpcId!);
now when I try to consume subnetIds (in this case, in awsx.ec2.Vpc.fromExistingIds....publicSubnetIds: subnetIds) I end up with:
error TS2740: Type 'Promise<string[]>' is missing the following properties from type 'Input<string>[]': length, pop, push, concat, and 26 more. againwhite-balloon-205
export let ccsubnetIds;
if ( config.createVpc == false ) {
ccsubnetIds = pulumi.concat(aws.ec2.getSubnetIds({ vpcId: vpcId, }));
}proud-alarm-92546
06/05/2019, 10:58 PMasync function getSubnetIds(vpcId: string): Promise<string[]> {
const res = await aws.ec2.getSubnetIds({ vpcId: vpcId });
return res.ids;
};
export const subnetIds = getSubnetIds(config.vpcId!);
let vpc2_manual = awsx.ec2.Vpc.fromExistingIds("vpc2_manual", {
vpcId: vpcId,
// this doesnt get populated automatically, and -fargateservice- only reads this from cluster.vpc.[pubic|private]....
publicSubnetIds: subnetIds
// privateSubnetIds: ...
}); is the consumer attempt
and publicSubnetIds: subnetIds returns:
error TS2740: Type 'Promise<string[]>' is missing the following properties from type 'Input<string>[]': length, pop, push, concat, and 26 more.white-balloon-205
publicSubnetIds property is apparently Input<string>[] instead of Input<string[]>.
I believe you will truly have to "go async" here. That is - put all of your code that creates resources dependent on these subnets inside an asynchronous callback. Possibly by putting it all inside a function which you only call from inside a then or async function.
Note that we're exploring being able to expose synchronous versions of these get* methods to significantly simplify this in the future - see https://github.com/pulumi/pulumi-terraform/issues/387.proud-alarm-92546
06/06/2019, 1:15 AMproud-alarm-92546
06/06/2019, 1:15 AM