Require the user to specify the AZ for the subnet

This commit is contained in:
hamilcarBarca17
2023-03-08 15:33:07 -07:00
parent 87538d511f
commit a06e201c93
5 changed files with 15 additions and 17 deletions
+3 -1
View File
@@ -14,6 +14,7 @@ const ACCOUNT_ID = "PLACEHOLDER"
const REGION = "us-east-1"
const VPC_ID = 'PLACEHOLDER'
const SUBNET_ID = 'PLACEHOLDER'
const SUBNET_AVAILABILITY_ZONE = 'PLACEHOLDER'
const user = app.node.tryGetContext("user");
if (!user) {
@@ -47,5 +48,6 @@ new G4ADStack(app, `TeamBuildingCloudGaming-${user}`, {
},
user,
vpcId: VPC_ID,
subnetId: SUBNET_ID
subnetId: SUBNET_ID,
subnetAvailabilityZone: SUBNET_AVAILABILITY_ZONE
});
+3 -2
View File
@@ -22,6 +22,7 @@ export interface BaseConfig extends StackProps {
readonly instanceSize: InstanceSize;
readonly vpcId: string;
readonly subnetId: string;
readonly subnetAvailabilityZone: string;
readonly sshKeyName: string;
readonly volumeSizeGiB: number;
readonly niceDCVDisplayDriverUrl: string;
@@ -37,7 +38,7 @@ export abstract class BaseEc2Stack extends Stack {
constructor(scope: App, id: string, props: BaseConfig) {
super(scope, id, props);
this.props = props;
const { vpcId, subnetId, sshKeyName, volumeSizeGiB, openPorts, allowInboundCidr, user } = props;
const { vpcId, subnetId, subnetAvailabilityZone, sshKeyName, volumeSizeGiB, openPorts, allowInboundCidr, user } = props;
const vpc = Vpc.fromLookup(this, "Vpc", { vpcId });
const securityGroup = new SecurityGroup(this, `SecurityGroup-${user}`, {
@@ -82,7 +83,7 @@ export abstract class BaseEc2Stack extends Stack {
instanceType: this.getInstanceType(),
vpc,
securityGroup,
vpcSubnets: vpc.selectSubnets({ subnets: [Subnet.fromSubnetAttributes(this, 'publicSubnet', {subnetId, availabilityZone: "us-east-1a"})] }),
vpcSubnets: vpc.selectSubnets({ subnets: [Subnet.fromSubnetAttributes(this, 'publicSubnet', {subnetId, availabilityZone: subnetAvailabilityZone})] }),
keyName: sshKeyName,
userData: this.getUserdata(),
machineImage: MachineImage.latestWindows(WindowsVersion.WINDOWS_SERVER_2019_ENGLISH_FULL_BASE),