-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from infoxchange/internal-testing-vpc-at-deploy…
…-time Delay VPC resolve to stack update time
- Loading branch information
Showing
4 changed files
with
14 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)], | ||
}; | ||
} | ||
} |