Aws-cdk: TargetGroup attribute not disabling

Created on 18 Oct 2019  路  3Comments  路  Source: aws/aws-cdk

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.

Reproduction Steps

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")

Error Log

Environment

  • CLI Version : 1.13.1 (build 96cfc63)
  • Framework Version: 1.12.0
  • OS : 64bit Mac OS X 10.15 19A583
  • Language : Python

Other

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

@aws-cdaws-elasticloadbalancing bug in-progress

Most helpful comment

Hi @nmussy

Cool I'm happy to open a PR for this and add the test.

All 3 comments

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:

Was this page helpful?
0 / 5 - 0 ratings