From 35b280616a420987b6553f73bc91a736b06d4e1a Mon Sep 17 00:00:00 2001 From: Arun Donti Date: Tue, 20 Sep 2022 09:21:35 -0400 Subject: [PATCH] fix(integ-tests): AwsApiCall Custom Resource length could be greater than 60 characters (#22119) Limits the resource type name to 60 characters to account for CloudFormation limitations with Custom Resource Resource Types Closes https://github.com/aws/aws-cdk/issues/22055 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../integ-tests/lib/assertions/sdk.ts | 8 ++++---- .../test/assertions/deploy-assert.test.ts | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts b/packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts index 97972e4c568ba..b79ecc4bce356 100644 --- a/packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts +++ b/packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts @@ -1,7 +1,7 @@ -import { CustomResource, Reference, Lazy, CfnResource, Stack, ArnFormat } from '@aws-cdk/core'; +import { ArnFormat, CfnResource, CustomResource, Lazy, Reference, Stack } from '@aws-cdk/core'; import { Construct, IConstruct } from 'constructs'; import { EqualsAssertion } from './assertions'; -import { ExpectedResult, ActualResult } from './common'; +import { ActualResult, ExpectedResult } from './common'; import { AssertionsProvider, SDK_RESOURCE_TYPE_PREFIX } from './providers'; /** @@ -113,7 +113,7 @@ export interface AwsApiCallOptions { /** * Options for creating an SDKQuery provider */ -export interface AwsApiCallProps extends AwsApiCallOptions {} +export interface AwsApiCallProps extends AwsApiCallOptions { } /** * Construct that creates a custom resource that will perform @@ -142,7 +142,7 @@ export class AwsApiCall extends Construct implements IAwsApiCall { flattenResponse: Lazy.string({ produce: () => this.flattenResponse }), salt: Date.now().toString(), }, - resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`, + resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`.substring(0, 60), }); // Needed so that all the policies set up by the provider should be available before the custom resource is provisioned. diff --git a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts index 5a287200e9fca..bbc2609822356 100644 --- a/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts +++ b/packages/@aws-cdk/integ-tests/test/assertions/deploy-assert.test.ts @@ -1,6 +1,6 @@ import { Template } from '@aws-cdk/assertions'; import { App, Stack } from '@aws-cdk/core'; -import { LogType, InvocationType, ExpectedResult, ActualResult } from '../../lib/assertions'; +import { ActualResult, ExpectedResult, InvocationType, LogType } from '../../lib/assertions'; import { DeployAssert } from '../../lib/assertions/private/deploy-assert'; describe('DeployAssert', () => { @@ -145,5 +145,22 @@ describe('DeployAssert', () => { template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi1', 1); template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi2', 1); }); + + test('custom resource type length is truncated when greater than 60 characters', () => { + // GIVEN + const app = new App(); + + // WHEN + const deplossert = new DeployAssert(app); + deplossert.awsApiCall('Pangram', 'TheQuickBrownFoxJumpsOverTheLazyDog'); + + // THEN + const truncatedType = 'Custom::DeployAssert@SdkCallPangramTheQuickBrownFoxJumpsOver'; + expect(truncatedType.length).toEqual(60); + + const template = Template.fromStack(deplossert.scope); + template.resourceCountIs('AWS::Lambda::Function', 1); + template.resourceCountIs(truncatedType, 1); + }); }); });