Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt IPAM functionality #1014

Merged
merged 7 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions awsx/ec2/subnetDistributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface SubnetSpec {

export function getSubnetSpecs(
vpcName: string,
vpcCidr: string,
vpcCidr: pulumi.Input<string>,
azNames: string[],
subnetInputs?: SubnetSpecInputs[],
): SubnetSpec[] {
Expand All @@ -42,7 +42,7 @@ export function getSubnetSpecs(
}

if (subnetInputs === undefined) {
return generateDefaultSubnets(vpcName, vpcCidr, azNames, azBases);
return generateDefaultSubnets(vpcName, azNames, azBases);
}

const ipAddress = require("ip-address");
Expand Down Expand Up @@ -147,7 +147,6 @@ export function getSubnetSpecs(

function generateDefaultSubnets(
vpcName: string,
vpcCidr: string,
azNames: string[],
azBases: string[],
): SubnetSpec[] {
Expand Down Expand Up @@ -178,7 +177,11 @@ function generateDefaultSubnets(
return Array.prototype.concat(privateSubnets, publicSubnets);
}

function cidrSubnetV4(ipRange: string, newBits: number, netNum: number): string {
function cidrSubnetV4(
ipRange: string | pulumi.Input<string>,
newBits: number,
netNum: number,
): string {
const ipAddress = require("ip-address");
const BigInteger = require("jsbn").BigInteger;

Expand Down
14 changes: 7 additions & 7 deletions awsx/ec2/vpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ export class Vpc extends schema.Vpc<VpcData> {
const allocationIds = args.natGateways?.elasticIpAllocationIds ?? [];
validateEips(natGatewayStrategy, allocationIds, availabilityZones);

const cidrBlock = args.cidrBlock ?? "10.0.0.0/16";

const subnetSpecs = getSubnetSpecs(name, cidrBlock, availabilityZones, args.subnetSpecs);
validateSubnets(subnetSpecs, getOverlappingSubnets);

validateNatGatewayStrategy(natGatewayStrategy, subnetSpecs);
if (args.cidrBlock && args.ipv4IpamPoolId) {
throw new Error("Only one of [cidrBlock] and [ipv4IpamPoolId] can be specified");
}

const sharedTags = { Name: name, ...args.tags };

const vpc = new aws.ec2.Vpc(
name,
{
...args,
cidrBlock,
tags: sharedTags,
},
{ parent: this },
);
const vpcId = vpc.id;

const subnetSpecs = getSubnetSpecs(name, vpc.cidrBlock, availabilityZones, args.subnetSpecs);
validateSubnets(subnetSpecs, getOverlappingSubnets);

validateNatGatewayStrategy(natGatewayStrategy, subnetSpecs);
// We unconditionally create the IGW (even if it's not needed because we
// only have isolated subnets) because AWS does not charge for it, and
// therefore there's no harm in adding it, whereas conditional resources
Expand Down