Skip to content

Commit

Permalink
Merge pull request #2 from infoxchange/internal-testing-vpc-at-deploy…
Browse files Browse the repository at this point in the history
…-time

Delay VPC resolve to stack update time
  • Loading branch information
callumgare committed Jul 9, 2024
2 parents a67eafe + 44add0b commit be7407d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ jobs:
- name: Build
run: npm run build

# The version commited to the repo is a string letting people know it's set on release. This causes semantic-release
# to fail so we set it to something valid here.
- name: Set version to a valid string
run: npm pkg set version=1.0.0

- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: npm audit signatures

Expand Down
7 changes: 1 addition & 6 deletions src/cdk-constructs/IxElasticache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ export class IxElasticache extends Construct {
// Setup VPC subnets
if (vpc && !vpcSubnetIds) {
if (deployConfig.isIxDeploy) {
vpcSubnetIds = [1, 2, 3].map((subnetNum) =>
StringParameter.valueForStringParameter(
scope,
`/vpc/subnet/private-${deployConfig.workloadGroup}/${subnetNum}/id`,
),
);
vpcSubnetIds = IxVpcDetails.getVpcSubnetIds(scope);
} else {
vpcSubnetIds = vpc.privateSubnets.map((subnet) => subnet.subnetId);

Expand Down
14 changes: 0 additions & 14 deletions src/cdk-constructs/IxNextjsSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ export class IxNextjsSite extends NextjsSite {
vpc: vpcDetails.vpc,
};
}
if (!props.cdk?.server || !("vpcSubnets" in props.cdk.server)) {
props.cdk = props.cdk ?? {};
props.cdk.server = {
...props.cdk.server,
vpcSubnets: vpcDetails.vpcSubnets,
};
}
if (!props.cdk?.revalidation || !("vpcSubnets" in props.cdk.revalidation)) {
props.cdk = props.cdk ?? {};
props.cdk.revalidation = {
...props.cdk.revalidation,
vpcSubnets: vpcDetails.vpcSubnets,
};
}
}

// This must be static because we need to call it in the constructor before super
Expand Down
23 changes: 13 additions & 10 deletions src/cdk-constructs/IxVpcDetails.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import { Construct } from "constructs";
import { StringParameter } from "aws-cdk-lib/aws-ssm";
import { Vpc, IVpc, SubnetSelection, SubnetFilter } from "aws-cdk-lib/aws-ec2";
import { Vpc, IVpc } from "aws-cdk-lib/aws-ec2";
import ixDeployConfig from "../deployConfig.js";

type ConstructScope = ConstructorParameters<typeof Construct>[0];
type ConstructId = ConstructorParameters<typeof Construct>[1];

export class IxVpcDetails extends Construct {
public vpc: IVpc;
public vpcSubnets: SubnetSelection;

constructor(scope: ConstructScope, id: ConstructId) {
super(scope, id);
this.vpc = this.getVpc(scope, id);
this.vpcSubnets = this.getVpcSubnet(scope);
}

private getVpc(scope: ConstructScope, id: ConstructId): IVpc {
const vpcId = StringParameter.valueFromLookup(scope, "/vpc/id");
return Vpc.fromLookup(scope, id + "-Vpc", { vpcId });
const vpcId = StringParameter.valueForStringParameter(scope, "/vpc/id");
return Vpc.fromVpcAttributes(this, id + "-Vpc", {
vpcId,
availabilityZones: [
"ap-southeast-2a",
"ap-southeast-2b",
"ap-southeast-2c",
],
isolatedSubnetIds: IxVpcDetails.getVpcSubnetIds(scope),
});
}

private getVpcSubnet(scope: ConstructScope): SubnetSelection {
const vpcSubnetIds = [1, 2, 3].map((subnetNum) =>
static getVpcSubnetIds(scope: ConstructScope): Array<string> {
return [1, 2, 3].map((subnetNum) =>
StringParameter.valueForStringParameter(
scope,
`/vpc/subnet/private-${ixDeployConfig.workloadGroup}/${subnetNum}/id`,
),
);
return {
subnetFilters: [SubnetFilter.byIds(vpcSubnetIds)],
};
}
}

0 comments on commit be7407d

Please sign in to comment.