Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Stop using deprecated getSubnetIds (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Hoban authored Jul 28, 2023
1 parent 1c027c6 commit afd4a34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions aws/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ export function getAvailabilityZones(opts?: pulumi.InvokeOptions): Promise<strin
// Only cache the results if 'opts' is not passed in. If there are opts, it may change the
// results and we can't necessarily reuse any previous results.
if (!zones) {
zones = aws.getAvailabilityZones(/*args:*/ undefined, { async: true }).then(r => r.names);
zones = aws.getAvailabilityZones(/*args:*/ undefined).then(r => r.names);
}

return zones;
}

return aws.getAvailabilityZones(/*args:*/ undefined, { ...opts, async: true }).then(r => r.names);
return aws.getAvailabilityZones(/*args:*/ undefined, { ...opts }).then(r => r.names);
}
34 changes: 20 additions & 14 deletions aws/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,31 @@ export class Network extends pulumi.ComponentResource {
*/
public static getDefault(opts?: pulumi.ComponentResourceOptions): Promise<Network> {
if (!defaultNetwork) {
const vpcResult = aws.ec2.getVpc({default: true}, { async: true });
const vpcResult = aws.ec2.getVpc({ default: true });
const self = this;

defaultNetwork = vpcResult.then(vpc => {
const vpcId = vpc.id;
const subnetIdsResult = aws.ec2.getSubnetIds({ vpcId }, { async: true });
const defaultSecurityGroupResult = aws.ec2.getSecurityGroup(
{ name: "default", vpcId }, { async: true });
const subnetIdsResult = aws.ec2.getSubnets({
filters: [
{ name: "vpc-id", values: [vpcId] },
],
});
const defaultSecurityGroupResult = aws.ec2.getSecurityGroup({
name: "default",
vpcId,
});

return Promise.all([subnetIdsResult, defaultSecurityGroupResult]).then(
([subnetIds, defaultSecurityGroup]) => {
const subnet0 = subnetIds.ids[0];
const subnet1 = subnetIds.ids[1];
return self.fromVpc("default-vpc", {
vpcId: vpcId,
subnetIds: [ subnet0, subnet1 ],
subnetIds: [subnet0, subnet1],
usePrivateSubnets: false,
securityGroupIds: [ defaultSecurityGroup.id ],
publicSubnetIds: [ subnet0, subnet1 ],
securityGroupIds: [defaultSecurityGroup.id],
publicSubnetIds: [subnet0, subnet1],
}, opts);
},
);
Expand Down Expand Up @@ -218,7 +224,7 @@ export class Network extends pulumi.ComponentResource {

this.vpcId = vpc.id;

this.securityGroupIds = [ vpc.defaultSecurityGroupId ];
this.securityGroupIds = [vpc.defaultSecurityGroupId];
this.subnetIds = [];
this.publicSubnetIds = [];

Expand All @@ -230,9 +236,9 @@ export class Network extends pulumi.ComponentResource {
const publicRouteTable = new aws.ec2.RouteTable(name, {
vpcId: vpc.id,
routes: [{
cidrBlock: "0.0.0.0/0",
gatewayId: internetGateway.id,
}],
cidrBlock: "0.0.0.0/0",
gatewayId: internetGateway.id,
}],
tags,
}, parentOpts);
this.publicRouteTableId = publicRouteTable.id;
Expand Down Expand Up @@ -266,8 +272,8 @@ export class Network extends pulumi.ComponentResource {
}

function createSubnetRouteTable(
network: Network, publicRouteTable: aws.ec2.RouteTable,
subnet: aws.ec2.Subnet, name: string, index: number) {
network: Network, publicRouteTable: aws.ec2.RouteTable,
subnet: aws.ec2.Subnet, name: string, index: number) {
const parentOpts = { parent: network };

if (!network.usePrivateSubnets) {
Expand All @@ -283,7 +289,7 @@ function createSubnetRouteTable(
const natGatewayPublicSubnet = new aws.ec2.Subnet(natName, {
vpcId: network.vpcId,
availabilityZone: getAvailabilityZone(index),
cidrBlock: `10.10.${index+64}.0/24`, // Use top half of the subnet space
cidrBlock: `10.10.${index + 64}.0/24`, // Use top half of the subnet space
mapPublicIpOnLaunch: true, // Always assign a public IP in NAT subnet
tags,
}, parentOpts);
Expand Down

0 comments on commit afd4a34

Please sign in to comment.