Skip to content

Commit

Permalink
feat(core): add vpcSubnets prop to HealthMonitor (#310)
Browse files Browse the repository at this point in the history
Fixes #305
  • Loading branch information
horsmand committed Feb 8, 2021
1 parent b9ad418 commit 12b6d89
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/aws-rfdk/lib/core/lib/health-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IConnectable,
IVpc,
Port,
SubnetSelection,
} from '@aws-cdk/aws-ec2';
import {
ApplicationLoadBalancer,
Expand Down Expand Up @@ -202,6 +203,13 @@ export interface HealthMonitorProps {
* @see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#deletion-protection
*/
readonly deletionProtection?: boolean;

/**
* Any load balancers that get created by calls to registerFleet() will be created in these subnets.
*
* @default: The VPC default strategy
*/
readonly vpcSubnets?: SubnetSelection;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/aws-rfdk/lib/core/lib/load-balancer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class LoadBalancerFactory {
const loadBalancer = new ApplicationLoadBalancer(scope, `ALB_${loadBalancerindex}`, {
vpc: this.vpc,
internetFacing: false,
vpcSubnets: healthMonitorProps.vpcSubnets,
deletionProtection: healthMonitorProps.deletionProtection ?? true,
});
// Enabling dropping of invalid HTTP header fields on the load balancer to prevent http smuggling attacks.
Expand Down
34 changes: 34 additions & 0 deletions packages/aws-rfdk/lib/core/test/health-monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
haveResourceLike,
not,
ABSENT,
notMatching,
stringLike,
} from '@aws-cdk/assert';
import {
AutoScalingGroup,
Expand All @@ -30,6 +32,7 @@ import {
InstanceSize,
InstanceType,
IVpc,
SubnetType,
Vpc,
} from '@aws-cdk/aws-ec2';
import {IApplicationLoadBalancerTarget} from '@aws-cdk/aws-elasticloadbalancingv2';
Expand Down Expand Up @@ -532,6 +535,37 @@ describe('HealthMonitor', () => {
}));
});

test('specifying a subnet', () => {
// WHEN
healthMonitor = new HealthMonitor(hmStack, 'healthMonitor2', {
vpc,
vpcSubnets: {
subnetType: SubnetType.PUBLIC,
},
});

const fleet = new TestMonitorableFleet(wfStack, 'workerFleet', {
vpc,
});
healthMonitor.registerFleet(fleet, {});

// THEN
// Make sure it has the public subnets
expectCDK(hmStack).to(haveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Subnets: [
{'Fn::ImportValue': stringLike('*PublicSubnet*')},
{'Fn::ImportValue': stringLike('*PublicSubnet*')},
],
}));
// Make sure the private subnets aren't present
expectCDK(hmStack).to(haveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Subnets: [
{'Fn::ImportValue': notMatching(stringLike('*PrivateSubnet*'))},
{'Fn::ImportValue': notMatching(stringLike('*PrivateSubnet*'))},
],
}));
});

describe('tagging', () => {
testConstructTags({
constructName: 'HealthMonitor',
Expand Down

0 comments on commit 12b6d89

Please sign in to comment.