From 22ab4b49402e3897670e49e559be25c84a824219 Mon Sep 17 00:00:00 2001 From: cohalz Date: Sun, 30 Jun 2019 20:08:23 +0900 Subject: [PATCH] fix(elasticloadbalancingv2): fix to be able to set deregistrationDelay (#3075) --- .../lib/shared/base-target-group.ts | 2 +- .../test/alb/test.listener.ts | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts index a81479faa36bf..04e9378b8ac40 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts @@ -205,7 +205,7 @@ export abstract class TargetGroupBase extends cdk.Construct implements ITargetGr super(scope, id); if (baseProps.deregistrationDelay !== undefined) { - this.setAttribute('deregistration_delay.timeout_seconds', baseProps.deregistrationDelay.toString()); + this.setAttribute('deregistration_delay.timeout_seconds', baseProps.deregistrationDelay.toSeconds().toString()); } this.healthCheck = baseProps.healthCheck || {}; diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts index bb635ef3774f4..0f8c18777fd22 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -1,7 +1,7 @@ import { expect, haveResource, MatchStyle } from '@aws-cdk/assert'; import ec2 = require('@aws-cdk/aws-ec2'); import cdk = require('@aws-cdk/core'); -import { ConstructNode } from '@aws-cdk/core'; +import { ConstructNode, Duration } from '@aws-cdk/core'; import { Test } from 'nodeunit'; import elbv2 = require('../../lib'); import { FakeSelfRegisteringTarget } from '../helpers'; @@ -534,6 +534,31 @@ export = { test.done(); }, + 'Can configure deregistration_delay for targets'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'Stack'); + + // WHEN + new elbv2.ApplicationTargetGroup(stack, 'TargetGroup', { + vpc, + port: 80, + deregistrationDelay: Duration.seconds(30) + }); + + // THEN + expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::TargetGroup', { + TargetGroupAttributes: [ + { + Key: "deregistration_delay.timeout_seconds", + Value: "30" + } + ] + })); + + test.done(); + }, + 'Throws with bad fixed responses': { 'status code'(test: Test) {