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(elasticloadbalancingv2): should allow more than 2 certificates #13332

Merged
merged 5 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,14 @@ export class ApplicationListener extends BaseListener implements IApplicationLis
this.certificateArns.push(first.certificateArn);
}

if (additionalCerts.length > 0) {
new ApplicationListenerCertificate(this, id, {
// Only one certificate can be specified per resource, even though
// `certificates` is of type Array
for (let i = 0; i < additionalCerts.length; i++) {
// ids should look like: `id`, `id2`, `id3` (for backwards-compatibility)
const certId = (i > 0) ? `${id}${i + 1}` : id;
new ApplicationListenerCertificate(this, certId, {
listener: this,
certificates: additionalCerts,
certificates: [additionalCerts[i]],
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,43 @@ describe('tests', () => {
});
});

test('HTTPS listener can add more than two certificates', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LB', { vpc });

// WHEN
const listener = lb.addListener('Listener', {
port: 443,
defaultTargetGroups: [
new elbv2.ApplicationTargetGroup(stack, 'Group', { vpc, port: 80 }),
],
certificates: [
elbv2.ListenerCertificate.fromArn('cert1'),
elbv2.ListenerCertificate.fromArn('cert2'),
elbv2.ListenerCertificate.fromArn('cert3'),
],
});

expect(listener.node.tryFindChild('DefaultCertificates')).toBeDefined();
expect(listener.node.tryFindChild('DefaultCertificates2')).toBeDefined();
expect(listener.node.tryFindChild('DefaultCertificates3')).not.toBeDefined();

// THEN
expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::Listener', {
Certificates: [{ CertificateArn: 'cert1' }],
});

expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::ListenerCertificate', {
Certificates: [{ CertificateArn: 'cert2' }],
});

expect(stack).toHaveResource('AWS::ElasticLoadBalancingV2::ListenerCertificate', {
Certificates: [{ CertificateArn: 'cert3' }],
});
});

test('Can configure targetType on TargetGroups', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down