Skip to content

Commit

Permalink
fix(aws-elasticloadbalancingv2): listener dependency (#1146)
Browse files Browse the repository at this point in the history
Fix taking a listener dependency for Network Load Balancers.

Fixes #1139.
  • Loading branch information
rix0rrr authored Nov 12, 2018
1 parent 72f0124 commit e9d3d93
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class NetworkListener extends BaseListener implements INetworkListener {
// New default target(s)
for (const targetGroup of targetGroups) {
this._addDefaultTargetGroup(targetGroup);
targetGroup.registerListener(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,22 @@ export class NetworkTargetGroup extends BaseTargetGroup {
*/
// tslint:disable-next-line:no-empty-interface
export interface INetworkTargetGroup extends ITargetGroup {
/**
* Register a listener that is load balancing to this target group.
*
* Don't call this directly. It will be called by listeners.
*/
registerListener(listener: INetworkListener): void;
}

/**
* An imported network target group
*/
class ImportedNetworkTargetGroup extends BaseImportedTargetGroup implements INetworkTargetGroup {
public registerListener(_listener: INetworkListener) {
// Nothing to do, we know nothing of our members
}

public listenerDependency(): cdk.IDependable {
return new LazyDependable([]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { expect, haveResource, MatchStyle } from '@aws-cdk/assert';
import ec2 = require('@aws-cdk/aws-ec2');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -112,4 +112,34 @@ export = {

test.done();
},

'Enable taking a dependency on an NLB target group\'s load balancer'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'Stack');
const lb = new elbv2.NetworkLoadBalancer(stack, 'LB', { vpc });
const listener = lb.addListener('Listener', { port: 443 });
const group = listener.addTargets('Group', {
port: 80,
targets: [new FakeSelfRegisteringTarget(stack, 'Target', vpc)]
});

// WHEN
const resource = new cdk.Resource(stack, 'MyResource', {
type: 'SomeResource',
});
resource.addDependency(group.listenerDependency());

// THEN
expect(stack).toMatch({
Resources: {
MyResource: {
Type: "SomeResource",
DependsOn: [ "LBListener49E825B4" ]
}
}
}, MatchStyle.SUPERSET);

test.done();
},
};

0 comments on commit e9d3d93

Please sign in to comment.