The NetworkTargetGroup
constructor has the proxy_protocol_v2
constructor prop. Setting this to True
correctly sets the attribute to enabled. However, when explicitly disabling by setting to False
the attribute is removed rather than updated.
Enable attribute:
target_group = network_listener.add_targets(
"TargetGroup",
port=80,
proxy_protocol_v2=True,
)
CloudFormation changeset:
[~] AWS::ElasticLoadBalancingV2::TargetGroup LoadBalancer/Listener/TargetGroupGroup LoadBalancerListenerTargetGroupGroup27D2B0EE
鈹斺攢 [+] TargetGroupAttributes
鈹斺攢 [{"Key":"proxy_protocol_v2.enabled","Value":"true"}]
Deploy
Disable attribute:
target_group = network_listener.add_targets(
"TargetGroup",
port=80,
proxy_protocol_v2=False,
)
Actual CloudFormation changeset:
[~] AWS::ElasticLoadBalancingV2::TargetGroup LoadBalancer/Listener/TargetGroupGroup LoadBalancerListenerTargetGroupGroup27D2B0EE
鈹斺攢 [-] TargetGroupAttributes
鈹斺攢 [{"Key":"proxy_protocol_v2.enabled","Value":"true"}]
Expected
[~] AWS::ElasticLoadBalancingV2::TargetGroup LoadBalancer/Listener/TargetGroupGroup LoadBalancerListenerTargetGroupGroup27D2B0EE
鈹斺攢 [~] TargetGroupAttributes
鈹斺攢 @@ -1,6 +1,6 @@
[ ] [
[ ] {
[ ] "Key": "proxy_protocol_v2.enabled",
[-] "Value": "true"
[+] "Value": "false"
[ ] }
[ ] ]
Workaround:
target_group.set_attribute("proxy_protocol_v2.enabled", "false")
Possible fix:
diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts
index 5fe5fc5a2..d5c0df41b 100644
--- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts
+++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/nlb/network-target-group.ts
@@ -54,8 +54,8 @@ export class NetworkTargetGroup extends TargetGroupBase implements INetworkTarge
this.listeners = [];
- if (props.proxyProtocolV2) {
- this.setAttribute('proxy_protocol_v2.enabled', 'true');
+ if (props.proxyProtocolV2 != null) {
+ this.setAttribute('proxy_protocol_v2.enabled', props.proxyProtocolV2 ? 'true' : 'false');
}
this.addTarget(...(props.targets || []));
This is :bug: Bug Report
Hey @v-do,
Thanks for the detailed issue. Would you like to open a PR yourself? Your patch looks great, all you would need is to add a test for it.
Otherwise, I'd be happy to pick it up.
Hi @nmussy
Cool I'm happy to open a PR for this and add the test.
Thanks @v-do :tada:
Most helpful comment
Hi @nmussy
Cool I'm happy to open a PR for this and add the test.