Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Add security group property to HealthMonitor #408

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,6 +14,7 @@ import {
import {SnsAction} from '@aws-cdk/aws-cloudwatch-actions';
import {
IConnectable,
ISecurityGroup,
IVpc,
Port,
SubnetSelection,
Expand Down Expand Up @@ -211,6 +212,13 @@ export interface HealthMonitorProps {
* @default: The VPC default strategy
*/
readonly vpcSubnets?: SubnetSelection;

/**
* Security group for the health monitor. This is security group is associated with the health monitor's load balancer.
*
* @default: A security group is created
*/
readonly securityGroup?: ISecurityGroup;
}

/**
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 @@ -200,6 +200,7 @@ export class LoadBalancerFactory {
internetFacing: false,
vpcSubnets: healthMonitorProps.vpcSubnets,
deletionProtection: healthMonitorProps.deletionProtection ?? true,
securityGroup: healthMonitorProps.securityGroup,
});
// Enabling dropping of invalid HTTP header fields on the load balancer to prevent http smuggling attacks.
loadBalancer.setAttribute('routing.http.drop_invalid_header_fields.enabled', 'true');
Expand Down
26 changes: 26 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 @@ -32,6 +32,7 @@ import {
InstanceSize,
InstanceType,
IVpc,
SecurityGroup,
SubnetType,
Vpc,
} from '@aws-cdk/aws-ec2';
Expand Down Expand Up @@ -567,6 +568,31 @@ describe('HealthMonitor', () => {
}));
});

test('specifying a security group', () => {
// GIVEN
const securityGroup = new SecurityGroup(infraStack, 'LBSecurityGroup', { vpc });
const fleet = new TestMonitorableFleet(wfStack, 'workerFleet', {
vpc,
});

// WHEN
healthMonitor = new HealthMonitor(hmStack, 'healthMonitor2', {
vpc,
securityGroup,
});
healthMonitor.registerFleet(fleet, {});

// THEN
// Make sure it has the security group
expectCDK(hmStack).to(haveResourceLike('AWS::ElasticLoadBalancingV2::LoadBalancer', {
SecurityGroups: arrayWith(
hmStack.resolve(securityGroup.securityGroupId),
),
}));
// HealthMonitor should not create its own security group
expectCDK(hmStack).notTo(haveResource('AWS::EC2::SecurityGroup'));
});

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