Skip to content

Commit

Permalink
fix(batch-alpha): cannot import FargateComputeEnvironment with fromFa…
Browse files Browse the repository at this point in the history
…rgateComputeEnvironmentArn (#25985)

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*
  • Loading branch information
lpizzinidev committed Jun 23, 2023
1 parent 4729d76 commit 05810f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 05810f4

Please sign in to comment.