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

feat: Adds NLB TLS Listener #2122

Merged
merged 15 commits into from
Apr 26, 2019
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cdk = require('@aws-cdk/cdk');
import { BaseListener } from '../shared/base-listener';
import { HealthCheck } from '../shared/base-target-group';
import { Protocol } from '../shared/enums';
import { Protocol, SslPolicy } from '../shared/enums';
import { INetworkLoadBalancer } from './network-load-balancer';
import { INetworkLoadBalancerTarget, INetworkTargetGroup, NetworkTargetGroup } from './network-target-group';

Expand All @@ -20,6 +20,31 @@ export interface BaseNetworkListenerProps {
* @default None
*/
readonly defaultTargetGroups?: INetworkTargetGroup[];

/**
* Protocol for listener, expects TCP or TLS
*/
readonly protocol?: Protocol;

/**
* Certificate list of ACM cert ARNs
*/
readonly certificates?: INetworkListenerCertificateProps[];

/**
* SSL Policy
*/
readonly sslPolicy?: SslPolicy;
}

/**
* Properties for adding a certificate to a listener
*/
export interface INetworkListenerCertificateProps {
/**
* Certificate ARN from ACM
*/
certificateArn: string
sthulb marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -49,10 +74,30 @@ export class NetworkListener extends BaseListener implements INetworkListener {
private readonly loadBalancer: INetworkLoadBalancer;

constructor(scope: cdk.Construct, id: string, props: NetworkListenerProps) {
const proto = props.protocol || Protocol.Tcp;
sthulb marked this conversation as resolved.
Show resolved Hide resolved

if ([Protocol.Tcp, Protocol.Tls].indexOf(proto) === -1) {
throw new Error(`The protocol must be either ${Protocol.Tcp} or ${Protocol.Tls}. Found ${props.protocol}`);
}

const certs = props.certificates || [];

if (proto === Protocol.Tls && (certs.length === 0 || certs.filter(v => {
sthulb marked this conversation as resolved.
Show resolved Hide resolved
return v.certificateArn == null;
}).length > 0)) {
throw new Error(`When the protocol is set to TLS, you must specify certificates`);
}

if (proto !== Protocol.Tls && certs.length > 0) {
throw new Error(`Protocol must be TLS when certificates have been specified`);
}

super(scope, id, {
loadBalancerArn: props.loadBalancer.loadBalancerArn,
protocol: Protocol.Tcp,
protocol: proto,
port: props.port,
sslPolicy: props.sslPolicy,
certificates: props.certificates
});

this.loadBalancer = props.loadBalancer;
Expand Down Expand Up @@ -108,7 +153,6 @@ export class NetworkListener extends BaseListener implements INetworkListener {
listenerArn: new cdk.CfnOutput(this, 'ListenerArn', { value: this.listenerArn }).makeImportValue().toString()
};
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export enum Protocol {
/**
* TCP
*/
Tcp = 'TCP'
Tcp = 'TCP',

/**
* TLS
*/
Tls = 'TLS'
}

/**
Expand Down
285 changes: 285 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-elasticloadbalancingv2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"pkglint": "^0.27.0"
},
"dependencies": {
"@aws-cdk/aws-certificatemanager": "^0.27.0",
"@aws-cdk/aws-cloudwatch": "^0.27.0",
"@aws-cdk/aws-codedeploy-api": "^0.27.0",
"@aws-cdk/aws-ec2": "^0.27.0",
Expand Down Expand Up @@ -92,4 +93,4 @@
"construct-ctor:@aws-cdk/aws-elasticloadbalancingv2.TargetGroupBase.<initializer>"
]
}
}
}
Loading