From 05810f44f3fa008c07c6fe39bacd2a00c52b32a0 Mon Sep 17 00:00:00 2001 From: Luca Pizzini Date: Fri, 23 Jun 2023 20:43:29 +0200 Subject: [PATCH] fix(batch-alpha): cannot import FargateComputeEnvironment with fromFargateComputeEnvironmentArn (#25985) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the superclass of the [Import](https://github.com/aws/aws-cdk/blob/104bf32798b02f8f3c3ec5aaa05e31c35b4a38da/packages/%40aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts#L1071) class instantiated by `fromFargateComputeEnvironmentArn` from `ManagedComputeEnvironmentBase` to `Resource`. This prevents errors due to the required `vpc` parameter of the old superclass [being passed](https://github.com/aws/aws-cdk/blob/104bf32798b02f8f3c3ec5aaa05e31c35b4a38da/packages/%40aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts#L1077-L1079) as `undefined`. Closes #25979. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-batch-alpha/lib/managed-compute-environment.ts | 10 ++++++---- .../test/managed-compute-environment.test.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts b/packages/@aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts index d5474bf0a9bf3..42308bb025919 100644 --- a/packages/@aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts +++ b/packages/@aws-cdk/aws-batch-alpha/lib/managed-compute-environment.ts @@ -1068,15 +1068,17 @@ export class FargateComputeEnvironment extends ManagedComputeEnvironmentBase imp const stack = Stack.of(scope); const computeEnvironmentName = stack.splitArn(fargateComputeEnvironmentArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName!; - class Import extends ManagedComputeEnvironmentBase implements IFargateComputeEnvironment { + class Import extends Resource implements IFargateComputeEnvironment { public readonly computeEnvironmentArn = fargateComputeEnvironmentArn; public readonly computeEnvironmentName = computeEnvironmentName; public readonly enabled = true; + public readonly maxvCpus = 1; + public readonly connections = { } as any; + public readonly securityGroups = []; + public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment'); } - return new Import(scope, id, { - vpc: undefined as any, - }); + return new Import(scope, id); } public readonly computeEnvironmentName: string; diff --git a/packages/@aws-cdk/aws-batch-alpha/test/managed-compute-environment.test.ts b/packages/@aws-cdk/aws-batch-alpha/test/managed-compute-environment.test.ts index de649bfe3daee..37fa4113934c2 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/managed-compute-environment.test.ts +++ b/packages/@aws-cdk/aws-batch-alpha/test/managed-compute-environment.test.ts @@ -935,4 +935,12 @@ describe('FargateComputeEnvironment', () => { ComputeEnvironmentName: 'maxPropsFargateCE', }); }); + + test('can be imported from arn', () => { + // WHEN + const ce = FargateComputeEnvironment.fromFargateComputeEnvironmentArn(stack, 'import', 'arn:aws:batch:us-east-1:123456789012:compute-environment/ce-name'); + + // THEN + expect(ce.computeEnvironmentArn).toEqual('arn:aws:batch:us-east-1:123456789012:compute-environment/ce-name'); + }); });