breezy-butcher-78604
09/15/2020, 3:45 AMgetVpc()
call immediately?{ async: false }
into the function might be what im looking for but the comments say this has been deprecated. is there new functionality that achieves this?little-cartoon-10569
09/15/2020, 3:46 AMawait
the promise.const vpcResult = await ec2.getVpc({default: true});
is about the smallest workable code?breezy-butcher-78604
09/15/2020, 3:49 AMindex.ts
and not inside an async
function so it complains about top-level await
. is there a way to do this without wrapping the whole template in an anonymous async function?little-cartoon-10569
09/15/2020, 3:49 AM.then()
.ec2.getVpc({ default: true}).then(result => {
console.log(JSON.stringify(result));
}
breezy-butcher-78604
09/15/2020, 3:51 AMlittle-cartoon-10569
09/15/2020, 3:51 AMbreezy-butcher-78604
09/15/2020, 3:58 AM// Grab VPC ID
const vpcId = (await aws.ec2.getVpc({ filters: [ /* filters here */ ] })).id;
// Grab a security group within the VPC
const sgId = (await aws.ec2.getSecurityGroup({ vpcId, filters: [ /* filters here */ ] })).id;
// Grab an array of subnets
const subnetIds = (await aws.ec2.getSubnetIds({ vpcId, filters: [ /* filters here */ ] })).ids;
subnetIds.forEach(subnetId => {
const instance = new aws.ec2.Instance('instance', { /* instance in subnet with above sg */ });
});
little-cartoon-10569
09/15/2020, 3:59 AMbreezy-butcher-78604
09/15/2020, 4:00 AM(async () => {
// Grab VPC ID
const vpcId = (await aws.ec2.getVpc({ filters: [ /* filters here */ ] })).id;
// Grab a security group within the VPC
const sgId = (await aws.ec2.getSecurityGroup({ vpcId, filters: [ /* filters here */ ] })).id;
// Grab an array of subnets
const subnetIds = (await aws.ec2.getSubnetIds({ vpcId, filters: [ /* filters here */ ] })).ids;
subnetIds.forEach(subnetId => {
const instance = new aws.ec2.Instance('instance', { /* instance in subnet with above sg */ });
});
})();
little-cartoon-10569
09/15/2020, 4:01 AMec2.Vpc.get()
or awsx.ec2.Vpc.initializeExistingVpcIdArgs()
? They provide some great Pulumi functions...initiInstancesInSubnets(vpcFilters, sgFilters, subnetFilters);
async function initiInstancesInSubnets(filters) {
const vpcId = await aws.ec2.getVpc({ filters: [ vpcFilters ] }).id;
const sgId = await aws.ec2.getSecurityGroup({ vpcId, filters: sgFilters }).id;
const subnetIds = (wait aws.ec2.getSubnetIds({ vpcId, filters: subnetFilters ] }).ids;
subnetIds.forEach(subnetId => {
const instance = new aws.ec2.Instance('instance', { /* instance in subnet with above sg */ });
});
breezy-butcher-78604
09/15/2020, 4:06 AMaws.ec2.Vpc.get()
existed, that might do what i needlittle-cartoon-10569
09/15/2020, 4:06 AMbreezy-butcher-78604
09/15/2020, 4:07 AMlittle-cartoon-10569
09/15/2020, 4:13 AMbreezy-butcher-78604
09/15/2020, 4:14 AM