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(aws-elasticloadbalancingv2): listener dependency #1146

Merged
merged 1 commit into from
Nov 12, 2018
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
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();
},
};