From 1e247d89adbc09ff79b87753fcd78b238a6752e8 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Thu, 9 Sep 2021 10:33:12 +0100 Subject: [PATCH] fix(apigatewayv2): ApiMapping does not depend on DomainName (#16201) When an ApiMapping resource is deployed using the Domain defined in the DomainName resource, the DomainName resource must be deployed before the ApiMapping resource. Since the current logic uses the CloudFormation Output of DomainName as a fall back, preferring the user provided string first, this dependency is not expressed in the resulting template. Remove the preference for the user provided string, will inform synthesis that the dependency must be declared. fixes #15464 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts | 2 +- .../aws-apigatewayv2/test/common/api-mapping.test.ts | 2 -- .../aws-apigatewayv2/test/http/domain-name.test.ts | 8 ++++++-- .../@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts | 6 +++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts b/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts index dca1a60bd4548..6b1123512c678 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/lib/common/domain-name.ts @@ -98,7 +98,7 @@ export class DomainName extends Resource implements IDomainName { ], }; const resource = new CfnDomainName(this, 'Resource', domainNameProps); - this.name = props.domainName ?? resource.ref; + this.name = resource.ref; this.regionalDomainName = Token.asString(resource.getAtt('RegionalDomainName')); this.regionalHostedZoneId = Token.asString(resource.getAtt('RegionalHostedZoneId')); } diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/common/api-mapping.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/common/api-mapping.test.ts index ff53d3dad11fc..855ad32dda137 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/common/api-mapping.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/common/api-mapping.test.ts @@ -26,7 +26,6 @@ describe('ApiMapping', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', Stage: '$default', }); }); @@ -58,7 +57,6 @@ describe('ApiMapping', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', Stage: 'beta', ApiMappingKey: 'beta', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts index 30c981a1da1d5..2d0d856c7ae15 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/http/domain-name.test.ts @@ -102,7 +102,9 @@ describe('DomainName', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', + DomainName: { + Ref: 'DNFDC76583', + }, Stage: 'beta', ApiMappingKey: 'beta', }); @@ -139,7 +141,9 @@ describe('DomainName', () => { ApiId: { Ref: 'ApiF70053CD', }, - DomainName: 'example.com', + DomainName: { + Ref: 'DNFDC76583', + }, Stage: '$default', }); }); diff --git a/packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts b/packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts index e7a05924719d3..b617fe4613a51 100644 --- a/packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2/test/http/stage.test.ts @@ -140,7 +140,11 @@ describe('HttpStage with domain mapping', () => { }, }); - expect(stage.domainUrl).toBe(`https://${domainName}/`); + expect(stack.resolve(stage.domainUrl)).toEqual({ + 'Fn::Join': ['', [ + 'https://', { Ref: 'DNFDC76583' }, '/', + ]], + }); }); test('domainUrl throws error if domainMapping is not configured', () => {