Skip to content

Commit

Permalink
Fix NLB health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdog committed Apr 22, 2024
1 parent ee2a709 commit a56ed5c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ export class Ec2HaBastion extends Construct implements ec2.IConnectable {
this.networkLoadBalancer = new elbv2.NetworkLoadBalancer(this, 'LB', {
vpc: props.vpc,
internetFacing: true,
// Public subnets
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
});

const listener = this.networkLoadBalancer.addListener('Listener', { port: 22 });
Expand All @@ -236,6 +240,13 @@ export class Ec2HaBastion extends Construct implements ec2.IConnectable {
for (const cidr of props.allowedCidrs) {
asg.connections.allowFrom(ec2.Peer.ipv4(cidr), ec2.Port.tcp(22));
}
// Also allow the NLB to connect to the ASG by allowing
// access from the public subnets, this allows the NLB to
// health check the instances.
for (const subnet of props.vpc.publicSubnets) {
const subnetPeer = ec2.Peer.ipv4(subnet.ipv4CidrBlock);
asg.connections.allowFrom(subnetPeer, ec2.Port.tcp(22));
}
} else if (props.openToInternet) {
asg.connections.allowFromAnyIpv4(ec2.Port.tcp(22));
} else {
Expand Down

0 comments on commit a56ed5c

Please sign in to comment.