Skip to content

Commit

Permalink
fix(batch): computeEnvironmentName is not set in FargateComputeEnviro…
Browse files Browse the repository at this point in the history
…nment (#25944)

computeEnvironmentName property was missing in FargateComputeEnvironment due to which ComputeEnvironmentName property set on the resulting AWS::Batch::ComputeEnvironment resource in the outputted CloudFormation.
Updated managed-compute-environment to reflect the fix made in FargateComputeEnvironment.

Closes #25794.
  • Loading branch information
akshaypilankar committed Jun 12, 2023
1 parent 79c58ed commit fb9f559
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@ export class FargateComputeEnvironment extends ManagedComputeEnvironmentBase imp
const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets);
const resource = new CfnComputeEnvironment(this, 'Resource', {
...baseManagedResourceProperties(this, subnetIds),
computeEnvironmentName: props.computeEnvironmentName,
computeResources: {
...baseManagedResourceProperties(this, subnetIds).computeResources as CfnComputeEnvironment.ComputeResourcesProperty,
type: this.spot ? 'FARGATE_SPOT' : 'FARGATE',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "31.0.0",
"version": "32.0.0",
"files": {
"6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0": {
"81f3134124cef368d56ccabda586dbcbef39a78089edd14c9d641cbcb4e0bad2": {
"source": {
"path": "batch-stack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0.json",
"objectKey": "81f3134124cef368d56ccabda586dbcbef39a78089edd14c9d641cbcb4e0bad2.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"Type": "AWS::Batch::ComputeEnvironment",
"Properties": {
"Type": "managed",
"ComputeEnvironmentName": "maxPropsFargateCE",
"ComputeResources": {
"MaxvCpus": 512,
"SecurityGroupIds": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"31.0.0"}
{"version":"32.0.0"}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"testCases": {
"BatchManagedComputeEnvironmentTest/DefaultTest": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "31.0.0",
"version": "32.0.0",
"artifacts": {
"batch-stack.assets": {
"type": "cdk:asset-manifest",
Expand All @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/81f3134124cef368d56ccabda586dbcbef39a78089edd14c9d641cbcb4e0bad2.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -192,7 +192,10 @@
"/batch-stack/maximalPropsFargate/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "maximalPropsFargate2D7D8138"
"data": "maximalPropsFargate2D7D8138",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
]
}
],
"/batch-stack/minimalPropsEc2/SecurityGroup/Resource": [
Expand Down Expand Up @@ -312,10 +315,7 @@
"/batch-stack/taggedCE/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "taggedCE5029E6F8",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
]
"data": "taggedCE5029E6F8"
}
],
"/batch-stack/BootstrapVersion": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@
"aws:cdk:cloudformation:type": "AWS::Batch::ComputeEnvironment",
"aws:cdk:cloudformation:props": {
"type": "managed",
"computeEnvironmentName": "maxPropsFargateCE",
"computeResources": {
"maxvCpus": 512,
"type": "FARGATE_SPOT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ArnPrincipal, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
import { Stack, Duration, Tags } from 'aws-cdk-lib';
import { capitalizePropertyNames } from './utils';
import * as batch from '../lib';
import { AllocationStrategy, ManagedEc2EcsComputeEnvironment, ManagedEc2EcsComputeEnvironmentProps, ManagedEc2EksComputeEnvironment, ManagedEc2EksComputeEnvironmentProps } from '../lib';
import { AllocationStrategy, ManagedEc2EcsComputeEnvironment, ManagedEc2EcsComputeEnvironmentProps, ManagedEc2EksComputeEnvironment, ManagedEc2EksComputeEnvironmentProps, FargateComputeEnvironment } from '../lib';
import { CfnComputeEnvironmentProps } from 'aws-cdk-lib/aws-batch';

const defaultExpectedEcsProps: CfnComputeEnvironmentProps = {
Expand Down Expand Up @@ -910,3 +910,29 @@ describe('ManagedEc2EksComputeEnvironment', () => {
});
});
});

describe('FargateComputeEnvironment', () => {
beforeEach(() => {
stack = new Stack();
vpc = new ec2.Vpc(stack, 'vpc');
});

test('respects name', () => {
// WHEN
new FargateComputeEnvironment(stack, 'maximalPropsFargate', {
vpc,
maxvCpus: 512,
computeEnvironmentName: 'maxPropsFargateCE',
replaceComputeEnvironment: true,
spot: true,
terminateOnUpdate: true,
updateTimeout: Duration.minutes(30),
updateToLatestImageVersion: false,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', {
ComputeEnvironmentName: 'maxPropsFargateCE',
});
});
});

0 comments on commit fb9f559

Please sign in to comment.