From ca6e8b0c049cb721f292ee5780f720c45b09c9d2 Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Thu, 18 May 2023 13:27:53 -0700 Subject: [PATCH 1/5] tags prop --- .../lib/managed-compute-environment.ts | 58 ++++++ .../batch-stack.assets.json | 4 +- .../batch-stack.template.json | 106 +++++++++++ .../manifest.json | 36 ++-- .../tree.json | 180 +++++++++++++++++- .../test/integ.managed-compute-environment.ts | 12 ++ .../test/managed-compute-environment.test.ts | 22 +++ 7 files changed, 399 insertions(+), 19 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 8077e716ae08a..88d34c24b984b 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 @@ -337,6 +337,14 @@ export interface IManagedEc2EcsComputeEnvironment extends IManagedComputeEnviron */ readonly placementGroup?: ec2.IPlacementGroup; + /** + * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. + * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. + * + * @default - no instance tags + */ + readonly instanceTags: { [key: string]: string }; + /** * Add an instance type to this compute environment */ @@ -346,6 +354,11 @@ export interface IManagedEc2EcsComputeEnvironment extends IManagedComputeEnviron * Add an instance class to this compute environment */ addInstanceClass(instanceClass: ec2.InstanceClass): void; + + /** + * Add an instance tag to this compute environment + */ + addInstanceTag(key: string, value: string): void; } /** @@ -569,6 +582,14 @@ export interface ManagedEc2EcsComputeEnvironmentProps extends ManagedComputeEnvi * @default - no placement group */ readonly placementGroup?: ec2.IPlacementGroup; + + /** + * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. + * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. + * + * @default - no instance tags + */ + readonly instanceTags?: { [key: string]: string }; } /** @@ -592,6 +613,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public readonly enabled = true; public readonly instanceClasses = []; public readonly instanceTypes = []; + public readonly instanceTags = {}; public readonly maxvCpus = 1; public readonly connections = { } as any; public readonly securityGroups = []; @@ -602,6 +624,9 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceType(_instanceType: ec2.InstanceType): void { throw new Error(`cannot add instance type to imported ComputeEnvironment '${id}'`); } + public addInstanceTag(_instanceTagKey: string, _instanceTagValue: string): void { + throw new Error(`cannot add instance tag to imported ComputeEnvironment '${id}'`); + } } return new Import(scope, id); @@ -619,6 +644,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public readonly launchTemplate?: ec2.ILaunchTemplate; public readonly minvCpus?: number; public readonly placementGroup?: ec2.IPlacementGroup; + public readonly instanceTags: { [key: string]: string }; private readonly instanceProfile: iam.CfnInstanceProfile; @@ -645,6 +671,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa this.launchTemplate = props.launchTemplate; this.minvCpus = props.minvCpus ?? DEFAULT_MIN_VCPUS; this.placementGroup = props.placementGroup; + this.instanceTags = props.instanceTags ?? {}; validateVCpus(id, this.minvCpus, this.maxvCpus); validateSpotConfig(id, this.spot, this.spotBidPercentage, this.spotFleetRole); @@ -694,6 +721,10 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceClass(instanceClass: ec2.InstanceClass): void { this.instanceClasses.push(instanceClass); } + + public addInstanceTag(key: string, value: string): void { + this.instanceTags[key] = value; + } } /** @@ -807,6 +838,14 @@ interface IManagedEc2EksComputeEnvironment extends IManagedComputeEnvironment { */ readonly placementGroup?: ec2.IPlacementGroup; + /** + * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. + * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. + * + * @default - no instance tags + */ + readonly instanceTags?: { [key: string]: string }; + /** * Add an instance type to this compute environment */ @@ -816,6 +855,11 @@ interface IManagedEc2EksComputeEnvironment extends IManagedComputeEnvironment { * Add an instance class to this compute environment */ addInstanceClass(instanceClass: ec2.InstanceClass): void; + + /** + * Add an instance tag to this compute environment + */ + addInstanceTag(key: string, value: string): void; } /** @@ -942,6 +986,14 @@ export interface ManagedEc2EksComputeEnvironmentProps extends ManagedComputeEnvi * @default - no placement group */ readonly placementGroup?: ec2.IPlacementGroup; + + /** + * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. + * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. + * + * @default - no instance tags + */ + readonly instanceTags?: { [key: string]: string }; } /** @@ -965,6 +1017,7 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa public readonly launchTemplate?: ec2.ILaunchTemplate; public readonly minvCpus?: number; public readonly placementGroup?: ec2.IPlacementGroup; + public readonly instanceTags: { [key: string]: string }; private readonly instanceProfile: iam.CfnInstanceProfile; @@ -990,6 +1043,7 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa this.launchTemplate = props.launchTemplate; this.minvCpus = props.minvCpus ?? DEFAULT_MIN_VCPUS; this.placementGroup = props.placementGroup; + this.instanceTags = props.instanceTags ?? {}; validateVCpus(id, this.minvCpus, this.maxvCpus); validateSpotConfig(id, this.spot, this.spotBidPercentage); @@ -1040,6 +1094,10 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceClass(instanceClass: ec2.InstanceClass): void { this.instanceClasses.push(instanceClass); } + + public addInstanceTag(key: string, value: string): void { + this.instanceTags[key] = value; + } } /** diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json index 2f0e3b17154d0..66cf1b3da84d7 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json @@ -1,7 +1,7 @@ { "version": "31.0.0", "files": { - "f47b7d60111f82dad5c04d0bef76e1b62fe75dc319951520566c9d9bce188d10": { + "c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32": { "source": { "path": "batch-stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "f47b7d60111f82dad5c04d0bef76e1b62fe75dc319951520566c9d9bce188d10.json", + "objectKey": "c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json index 0b0ccd376482a..e41f99574eb6b 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json @@ -882,6 +882,112 @@ "State": "ENABLED", "UpdatePolicy": {} } + }, + "taggedCESecurityGroup82CCF59F": { + "Type": "AWS::EC2::SecurityGroup", + "Properties": { + "GroupDescription": "batch-stack/taggedCE/SecurityGroup", + "SecurityGroupEgress": [ + { + "CidrIp": "0.0.0.0/0", + "Description": "Allow all outbound traffic by default", + "IpProtocol": "-1" + } + ], + "VpcId": { + "Ref": "vpcA2121C38" + } + } + }, + "taggedCEInstanceProfileRoleC239DAF9": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" + ] + ] + } + ] + } + }, + "taggedCEInstanceProfileB29F2197": { + "Type": "AWS::IAM::InstanceProfile", + "Properties": { + "Roles": [ + { + "Ref": "taggedCEInstanceProfileRoleC239DAF9" + } + ] + } + }, + "taggedCE5029E6F8": { + "Type": "AWS::Batch::ComputeEnvironment", + "Properties": { + "Type": "managed", + "ComputeResources": { + "AllocationStrategy": "BEST_FIT_PROGRESSIVE", + "Ec2Configuration": [ + { + "ImageIdOverride": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "ImageType": "ECS_AL2" + } + ], + "InstanceRole": { + "Fn::GetAtt": [ + "taggedCEInstanceProfileB29F2197", + "Arn" + ] + }, + "InstanceTypes": [ + "optimal" + ], + "MaxvCpus": 256, + "MinvCpus": 0, + "SecurityGroupIds": [ + { + "Fn::GetAtt": [ + "taggedCESecurityGroup82CCF59F", + "GroupId" + ] + } + ], + "Subnets": [ + { + "Ref": "vpcPrivateSubnet1Subnet934893E8" + }, + { + "Ref": "vpcPrivateSubnet2Subnet7031C2BA" + } + ], + "Type": "EC2", + "UpdateToLatestImageVersion": true + }, + "ReplaceComputeEnvironment": false, + "State": "ENABLED", + "UpdatePolicy": {} + } } }, "Parameters": { diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json index b0cfa1b0b3bed..af3a755891c26 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json @@ -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}/f47b7d60111f82dad5c04d0bef76e1b62fe75dc319951520566c9d9bce188d10.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -291,34 +291,40 @@ "data": "SpotEc2A0470C83" } ], - "/batch-stack/BootstrapVersion": [ + "/batch-stack/taggedCE/SecurityGroup/Resource": [ { "type": "aws:cdk:logicalId", - "data": "BootstrapVersion" + "data": "taggedCESecurityGroup82CCF59F" } ], - "/batch-stack/CheckBootstrapVersion": [ + "/batch-stack/taggedCE/InstanceProfileRole/Resource": [ { "type": "aws:cdk:logicalId", - "data": "CheckBootstrapVersion" + "data": "taggedCEInstanceProfileRoleC239DAF9" + } + ], + "/batch-stack/taggedCE/InstanceProfile": [ + { + "type": "aws:cdk:logicalId", + "data": "taggedCEInstanceProfileB29F2197" } ], - "minimalPropsFargate8E9B9556": [ + "/batch-stack/taggedCE/Resource": [ { "type": "aws:cdk:logicalId", - "data": "minimalPropsFargate8E9B9556", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] + "data": "taggedCE5029E6F8" } ], - "maximalPropsFargateA2E688D8": [ + "/batch-stack/BootstrapVersion": [ + { + "type": "aws:cdk:logicalId", + "data": "BootstrapVersion" + } + ], + "/batch-stack/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", - "data": "maximalPropsFargateA2E688D8", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] + "data": "CheckBootstrapVersion" } ] }, diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json index f9e0f8c3e62a6..3ef44a5f9a619 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json @@ -1504,6 +1504,182 @@ "version": "0.0.0" } }, + "taggedCE": { + "id": "taggedCE", + "path": "batch-stack/taggedCE", + "children": { + "SecurityGroup": { + "id": "SecurityGroup", + "path": "batch-stack/taggedCE/SecurityGroup", + "children": { + "Resource": { + "id": "Resource", + "path": "batch-stack/taggedCE/SecurityGroup/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::EC2::SecurityGroup", + "aws:cdk:cloudformation:props": { + "groupDescription": "batch-stack/taggedCE/SecurityGroup", + "securityGroupEgress": [ + { + "cidrIp": "0.0.0.0/0", + "description": "Allow all outbound traffic by default", + "ipProtocol": "-1" + } + ], + "vpcId": { + "Ref": "vpcA2121C38" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.CfnSecurityGroup", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_ec2.SecurityGroup", + "version": "0.0.0" + } + }, + "InstanceProfileRole": { + "id": "InstanceProfileRole", + "path": "batch-stack/taggedCE/InstanceProfileRole", + "children": { + "ImportInstanceProfileRole": { + "id": "ImportInstanceProfileRole", + "path": "batch-stack/taggedCE/InstanceProfileRole/ImportInstanceProfileRole", + "constructInfo": { + "fqn": "aws-cdk-lib.Resource", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "batch-stack/taggedCE/InstanceProfileRole/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::Role", + "aws:cdk:cloudformation:props": { + "assumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "ec2.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "managedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role" + ] + ] + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnRole", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.Role", + "version": "0.0.0" + } + }, + "InstanceProfile": { + "id": "InstanceProfile", + "path": "batch-stack/taggedCE/InstanceProfile", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::IAM::InstanceProfile", + "aws:cdk:cloudformation:props": { + "roles": [ + { + "Ref": "taggedCEInstanceProfileRoleC239DAF9" + } + ] + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_iam.CfnInstanceProfile", + "version": "0.0.0" + } + }, + "Resource": { + "id": "Resource", + "path": "batch-stack/taggedCE/Resource", + "attributes": { + "aws:cdk:cloudformation:type": "AWS::Batch::ComputeEnvironment", + "aws:cdk:cloudformation:props": { + "type": "managed", + "computeResources": { + "maxvCpus": 256, + "type": "EC2", + "updateToLatestImageVersion": true, + "securityGroupIds": [ + { + "Fn::GetAtt": [ + "taggedCESecurityGroup82CCF59F", + "GroupId" + ] + } + ], + "subnets": [ + { + "Ref": "vpcPrivateSubnet1Subnet934893E8" + }, + { + "Ref": "vpcPrivateSubnet2Subnet7031C2BA" + } + ], + "minvCpus": 0, + "instanceRole": { + "Fn::GetAtt": [ + "taggedCEInstanceProfileB29F2197", + "Arn" + ] + }, + "instanceTypes": [ + "optimal" + ], + "allocationStrategy": "BEST_FIT_PROGRESSIVE", + "ec2Configuration": [ + { + "imageIdOverride": { + "Ref": "SsmParameterValueawsserviceamiamazonlinuxlatestamznamihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter" + }, + "imageType": "ECS_AL2" + } + ] + }, + "replaceComputeEnvironment": false, + "state": "ENABLED", + "updatePolicy": {} + } + }, + "constructInfo": { + "fqn": "aws-cdk-lib.aws_batch.CfnComputeEnvironment", + "version": "0.0.0" + } + } + }, + "constructInfo": { + "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", + "version": "0.0.0" + } + }, "BootstrapVersion": { "id": "BootstrapVersion", "path": "batch-stack/BootstrapVersion", @@ -1539,7 +1715,7 @@ "path": "BatchManagedComputeEnvironmentTest/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.270" + "version": "10.2.26" } }, "DeployAssert": { @@ -1585,7 +1761,7 @@ "path": "Tree", "constructInfo": { "fqn": "constructs.Construct", - "version": "10.1.270" + "version": "10.2.26" } } }, diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts index d19e596f9ad0a..d04a64bb13495 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts @@ -59,6 +59,18 @@ new ManagedEc2EcsComputeEnvironment(stack, 'SpotEc2', { }), }); +const taggedEc2Ecs = new ManagedEc2EcsComputeEnvironment(stack, 'taggedCE', { + vpc, + images: [{ + image: new ec2.AmazonLinuxImage(), + }], + instanceTags: { + key: 'value', + }, +}); + +taggedEc2Ecs.addInstanceTag('foo', 'bar'); + new integ.IntegTest(app, 'BatchManagedComputeEnvironmentTest', { testCases: [stack], }); 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 a92ba6b69a896..4f667cc729281 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 @@ -565,6 +565,28 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }); }); + test('respects instanceTags', () => { + // WHEN + const ce = new ComputeEnvironment(stack, 'MyCE', { + ...defaultProps, + updateToLatestImageVersion: false, + instanceTags: { + boo: 'bah', + }, + }); + + ce.addInstanceTag('key', 'value'); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', { + ...expectedProps, + ComputeResources: { + ...defaultComputeResources, + UpdateToLatestImageVersion: false, + }, + }); + }); + test('can be imported from arn', () => { // WHEN const ce = ManagedEc2EcsComputeEnvironment.fromManagedEc2EcsComputeEnvironmentArn(stack, 'import', 'arn:aws:batch:us-east-1:123456789012:compute-environment/ce-name'); From 986ba5034f194aeac1f96e1831727945249e3e76 Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Thu, 18 May 2023 13:37:16 -0700 Subject: [PATCH 2/5] readme --- packages/@aws-cdk/aws-batch-alpha/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/@aws-cdk/aws-batch-alpha/README.md b/packages/@aws-cdk/aws-batch-alpha/README.md index 806befb9edad4..436d5b99a4511 100644 --- a/packages/@aws-cdk/aws-batch-alpha/README.md +++ b/packages/@aws-cdk/aws-batch-alpha/README.md @@ -204,6 +204,22 @@ new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', { }); ``` +### Tagging Instances + +You can tag any instances launched by your managed EC2 ComputeEnvironments by specifying the `instanceTags` property or +calling the `addInstanceTag()` method: + +```ts +const tagCE = new batch.ManagedEc2EcsComputeEnvironment(this, 'CEThatMakesTaggedInstnaces', { + vpc, + instanceTags: { + key: 'value', + }, +}); + +tagCE.addInstanceTag('key2', 'value2'); +``` + Unmanaged `ComputeEnvironment`s do not support `maxvCpus` or `minvCpus` because you must provision and manage the instances yourself; that is, Batch will not scale them up and down as needed. From 7fa5dad70477272c6b4eb98cb0481f5a9a73dcb5 Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Thu, 18 May 2023 14:20:25 -0700 Subject: [PATCH 3/5] template --- .../lib/managed-compute-environment.ts | 6 ++++++ .../batch-stack.assets.json | 4 ++-- .../batch-stack.template.json | 4 ++++ .../manifest.json | 2 +- .../tree.json | 18 +++++++++++------- .../test/managed-compute-environment.test.ts | 6 ++++-- 6 files changed, 28 insertions(+), 12 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 88d34c24b984b..1a65b58664b55 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 @@ -701,6 +701,9 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa }; }), placementGroup: this.placementGroup?.placementGroupName, + tags: Lazy.any({ + produce: () => Object.keys(this.instanceTags).length === 0 ? undefined : this.instanceTags, + }) as any, }, }); @@ -1074,6 +1077,9 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa }; }), placementGroup: this.placementGroup?.placementGroupName, + tags: Lazy.any({ + produce: () => Object.keys(this.instanceTags).length === 0 ? undefined : this.instanceTags, + }) as any, }, }); diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json index 66cf1b3da84d7..0334216abaf09 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json @@ -1,7 +1,7 @@ { "version": "31.0.0", "files": { - "c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32": { + "ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a": { "source": { "path": "batch-stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32.json", + "objectKey": "ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json index e41f99574eb6b..6a4428fd5d069 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json @@ -981,6 +981,10 @@ "Ref": "vpcPrivateSubnet2Subnet7031C2BA" } ], + "Tags": { + "key": "value", + "foo": "bar" + }, "Type": "EC2", "UpdateToLatestImageVersion": true }, diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json index af3a755891c26..59a818f8d28cd 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json @@ -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}/c8c954792912d6b8c536b91ed5e20a6de81e0b06cb012c43fe79a8b782108b32.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json index 3ef44a5f9a619..cf2dafaa37776 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json @@ -729,7 +729,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.FargateComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -814,7 +814,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.FargateComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -990,7 +990,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -1274,7 +1274,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -1500,7 +1500,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, @@ -1662,7 +1662,11 @@ }, "imageType": "ECS_AL2" } - ] + ], + "tags": { + "key": "value", + "foo": "bar" + } }, "replaceComputeEnvironment": false, "state": "ENABLED", @@ -1676,7 +1680,7 @@ } }, "constructInfo": { - "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", + "fqn": "aws-cdk-lib.Resource", "version": "0.0.0" } }, 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 4f667cc729281..c8330a8bb1141 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 @@ -569,7 +569,6 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] // WHEN const ce = new ComputeEnvironment(stack, 'MyCE', { ...defaultProps, - updateToLatestImageVersion: false, instanceTags: { boo: 'bah', }, @@ -582,7 +581,10 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] ...expectedProps, ComputeResources: { ...defaultComputeResources, - UpdateToLatestImageVersion: false, + Tags: { + boo: 'bah', + key: 'value', + }, }, }); }); From 5acba60bd5afccbedd54238054dd3337453ae85a Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Thu, 18 May 2023 15:11:43 -0700 Subject: [PATCH 4/5] rosetaa...... --- packages/@aws-cdk/aws-batch-alpha/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/@aws-cdk/aws-batch-alpha/README.md b/packages/@aws-cdk/aws-batch-alpha/README.md index 436d5b99a4511..a7419772ba09b 100644 --- a/packages/@aws-cdk/aws-batch-alpha/README.md +++ b/packages/@aws-cdk/aws-batch-alpha/README.md @@ -210,6 +210,8 @@ You can tag any instances launched by your managed EC2 ComputeEnvironments by sp calling the `addInstanceTag()` method: ```ts +declare const vpc: ec2.IVpc; + const tagCE = new batch.ManagedEc2EcsComputeEnvironment(this, 'CEThatMakesTaggedInstnaces', { vpc, instanceTags: { From 64842883a53b1f9640afcb1d7a6b0e0cc71be29c Mon Sep 17 00:00:00 2001 From: Calvin Combs Date: Tue, 23 May 2023 15:36:34 -0700 Subject: [PATCH 5/5] tags.of --- packages/@aws-cdk/aws-batch-alpha/README.md | 10 ++- .../lib/managed-compute-environment.ts | 72 ++----------------- .../batch-stack.assets.json | 4 +- .../batch-stack.template.json | 28 +++++++- .../manifest.json | 7 +- .../tree.json | 40 ++++++++--- .../test/integ.managed-compute-environment.ts | 8 +-- .../test/managed-compute-environment.test.ts | 14 ++-- 8 files changed, 84 insertions(+), 99 deletions(-) diff --git a/packages/@aws-cdk/aws-batch-alpha/README.md b/packages/@aws-cdk/aws-batch-alpha/README.md index a7419772ba09b..e29b5b0a5cf97 100644 --- a/packages/@aws-cdk/aws-batch-alpha/README.md +++ b/packages/@aws-cdk/aws-batch-alpha/README.md @@ -206,20 +206,18 @@ new batch.ManagedEc2EcsComputeEnvironment(this, 'myEc2ComputeEnv', { ### Tagging Instances -You can tag any instances launched by your managed EC2 ComputeEnvironments by specifying the `instanceTags` property or -calling the `addInstanceTag()` method: +You can tag any instances launched by your managed EC2 ComputeEnvironments by using the CDK `Tags` API: ```ts +import { Tags } from 'aws-cdk-lib'; + declare const vpc: ec2.IVpc; const tagCE = new batch.ManagedEc2EcsComputeEnvironment(this, 'CEThatMakesTaggedInstnaces', { vpc, - instanceTags: { - key: 'value', - }, }); -tagCE.addInstanceTag('key2', 'value2'); +Tags.of(tagCE).add('super', 'salamander'); ``` Unmanaged `ComputeEnvironment`s do not support `maxvCpus` or `minvCpus` because you must provision and manage the instances yourself; 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 1a65b58664b55..2725d92dc0b69 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 @@ -2,7 +2,7 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as eks from 'aws-cdk-lib/aws-eks'; import * as iam from 'aws-cdk-lib/aws-iam'; import { IRole } from 'aws-cdk-lib/aws-iam'; -import { ArnFormat, Duration, Lazy, Resource, Stack } from 'aws-cdk-lib'; +import { ArnFormat, Duration, ITaggable, Lazy, Resource, Stack, TagManager, TagType } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import { CfnComputeEnvironment } from 'aws-cdk-lib/aws-batch'; import { IComputeEnvironment, ComputeEnvironmentBase, ComputeEnvironmentProps } from './compute-environment-base'; @@ -12,7 +12,7 @@ import { IComputeEnvironment, ComputeEnvironmentBase, ComputeEnvironmentProps } * Represents a Managed ComputeEnvironment. Batch will provision EC2 Instances to * meet the requirements of the jobs executing in this ComputeEnvironment. */ -export interface IManagedComputeEnvironment extends IComputeEnvironment, ec2.IConnectable { +export interface IManagedComputeEnvironment extends IComputeEnvironment, ec2.IConnectable, ITaggable { /** * The maximum vCpus this `ManagedComputeEnvironment` can scale up to. * @@ -206,6 +206,7 @@ export abstract class ManagedComputeEnvironmentBase extends ComputeEnvironmentBa public readonly terminateOnUpdate?: boolean; public readonly securityGroups: ec2.ISecurityGroup[]; public readonly updateToLatestImageVersion?: boolean; + public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment'); public readonly connections: ec2.Connections; @@ -337,14 +338,6 @@ export interface IManagedEc2EcsComputeEnvironment extends IManagedComputeEnviron */ readonly placementGroup?: ec2.IPlacementGroup; - /** - * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. - * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. - * - * @default - no instance tags - */ - readonly instanceTags: { [key: string]: string }; - /** * Add an instance type to this compute environment */ @@ -354,11 +347,6 @@ export interface IManagedEc2EcsComputeEnvironment extends IManagedComputeEnviron * Add an instance class to this compute environment */ addInstanceClass(instanceClass: ec2.InstanceClass): void; - - /** - * Add an instance tag to this compute environment - */ - addInstanceTag(key: string, value: string): void; } /** @@ -582,14 +570,6 @@ export interface ManagedEc2EcsComputeEnvironmentProps extends ManagedComputeEnvi * @default - no placement group */ readonly placementGroup?: ec2.IPlacementGroup; - - /** - * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. - * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. - * - * @default - no instance tags - */ - readonly instanceTags?: { [key: string]: string }; } /** @@ -613,10 +593,10 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public readonly enabled = true; public readonly instanceClasses = []; public readonly instanceTypes = []; - public readonly instanceTags = {}; public readonly maxvCpus = 1; public readonly connections = { } as any; public readonly securityGroups = []; + public readonly tags: TagManager = new TagManager(TagType.MAP, 'AWS::Batch::ComputeEnvironment'); public addInstanceClass(_instanceClass: ec2.InstanceClass): void { throw new Error(`cannot add instance class to imported ComputeEnvironment '${id}'`); @@ -624,9 +604,6 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceType(_instanceType: ec2.InstanceType): void { throw new Error(`cannot add instance type to imported ComputeEnvironment '${id}'`); } - public addInstanceTag(_instanceTagKey: string, _instanceTagValue: string): void { - throw new Error(`cannot add instance tag to imported ComputeEnvironment '${id}'`); - } } return new Import(scope, id); @@ -644,7 +621,6 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public readonly launchTemplate?: ec2.ILaunchTemplate; public readonly minvCpus?: number; public readonly placementGroup?: ec2.IPlacementGroup; - public readonly instanceTags: { [key: string]: string }; private readonly instanceProfile: iam.CfnInstanceProfile; @@ -671,7 +647,6 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa this.launchTemplate = props.launchTemplate; this.minvCpus = props.minvCpus ?? DEFAULT_MIN_VCPUS; this.placementGroup = props.placementGroup; - this.instanceTags = props.instanceTags ?? {}; validateVCpus(id, this.minvCpus, this.maxvCpus); validateSpotConfig(id, this.spot, this.spotBidPercentage, this.spotFleetRole); @@ -701,9 +676,7 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa }; }), placementGroup: this.placementGroup?.placementGroupName, - tags: Lazy.any({ - produce: () => Object.keys(this.instanceTags).length === 0 ? undefined : this.instanceTags, - }) as any, + tags: this.tags.renderedTags as any, }, }); @@ -724,10 +697,6 @@ export class ManagedEc2EcsComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceClass(instanceClass: ec2.InstanceClass): void { this.instanceClasses.push(instanceClass); } - - public addInstanceTag(key: string, value: string): void { - this.instanceTags[key] = value; - } } /** @@ -841,14 +810,6 @@ interface IManagedEc2EksComputeEnvironment extends IManagedComputeEnvironment { */ readonly placementGroup?: ec2.IPlacementGroup; - /** - * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. - * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. - * - * @default - no instance tags - */ - readonly instanceTags?: { [key: string]: string }; - /** * Add an instance type to this compute environment */ @@ -858,11 +819,6 @@ interface IManagedEc2EksComputeEnvironment extends IManagedComputeEnvironment { * Add an instance class to this compute environment */ addInstanceClass(instanceClass: ec2.InstanceClass): void; - - /** - * Add an instance tag to this compute environment - */ - addInstanceTag(key: string, value: string): void; } /** @@ -989,14 +945,6 @@ export interface ManagedEc2EksComputeEnvironmentProps extends ManagedComputeEnvi * @default - no placement group */ readonly placementGroup?: ec2.IPlacementGroup; - - /** - * Key-value pair tags to be applied to EC2 resources that are launched in the compute environment. - * These tags aren't seen when using the AWS Batch ListTagsForResource API operation. - * - * @default - no instance tags - */ - readonly instanceTags?: { [key: string]: string }; } /** @@ -1020,7 +968,6 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa public readonly launchTemplate?: ec2.ILaunchTemplate; public readonly minvCpus?: number; public readonly placementGroup?: ec2.IPlacementGroup; - public readonly instanceTags: { [key: string]: string }; private readonly instanceProfile: iam.CfnInstanceProfile; @@ -1046,7 +993,6 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa this.launchTemplate = props.launchTemplate; this.minvCpus = props.minvCpus ?? DEFAULT_MIN_VCPUS; this.placementGroup = props.placementGroup; - this.instanceTags = props.instanceTags ?? {}; validateVCpus(id, this.minvCpus, this.maxvCpus); validateSpotConfig(id, this.spot, this.spotBidPercentage); @@ -1077,9 +1023,7 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa }; }), placementGroup: this.placementGroup?.placementGroupName, - tags: Lazy.any({ - produce: () => Object.keys(this.instanceTags).length === 0 ? undefined : this.instanceTags, - }) as any, + tags: this.tags.renderedTags as any, }, }); @@ -1100,10 +1044,6 @@ export class ManagedEc2EksComputeEnvironment extends ManagedComputeEnvironmentBa public addInstanceClass(instanceClass: ec2.InstanceClass): void { this.instanceClasses.push(instanceClass); } - - public addInstanceTag(key: string, value: string): void { - this.instanceTags[key] = value; - } } /** diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json index 0334216abaf09..7a42d47a88c9b 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.assets.json @@ -1,7 +1,7 @@ { "version": "31.0.0", "files": { - "ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a": { + "6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0": { "source": { "path": "batch-stack.template.json", "packaging": "file" @@ -9,7 +9,7 @@ "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a.json", + "objectKey": "6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json index 6a4428fd5d069..39f6afe175e92 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/batch-stack.template.json @@ -894,6 +894,16 @@ "IpProtocol": "-1" } ], + "Tags": [ + { + "Key": "foo", + "Value": "bar" + }, + { + "Key": "super", + "Value": "salamander" + } + ], "VpcId": { "Ref": "vpcA2121C38" } @@ -927,6 +937,16 @@ ] ] } + ], + "Tags": [ + { + "Key": "foo", + "Value": "bar" + }, + { + "Key": "super", + "Value": "salamander" + } ] } }, @@ -982,14 +1002,18 @@ } ], "Tags": { - "key": "value", - "foo": "bar" + "foo": "bar", + "super": "salamander" }, "Type": "EC2", "UpdateToLatestImageVersion": true }, "ReplaceComputeEnvironment": false, "State": "ENABLED", + "Tags": { + "foo": "bar", + "super": "salamander" + }, "UpdatePolicy": {} } } diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json index 59a818f8d28cd..a34d57abde72f 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/manifest.json @@ -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}/ba920705b83f88b051d5b8d11dbeca350a902eba11541e79056dd8d2c2fbc79a.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6ebdcdec29ca32bb55c4daa83140fbc6af6c8a2663beb1c1a833a3d4c6ee12c0.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ @@ -312,7 +312,10 @@ "/batch-stack/taggedCE/Resource": [ { "type": "aws:cdk:logicalId", - "data": "taggedCE5029E6F8" + "data": "taggedCE5029E6F8", + "trace": [ + "!!DESTRUCTIVE_CHANGES: WILL_REPLACE" + ] } ], "/batch-stack/BootstrapVersion": [ diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json index cf2dafaa37776..8b24aaded4e56 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.js.snapshot/tree.json @@ -729,7 +729,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.FargateComputeEnvironment", "version": "0.0.0" } }, @@ -814,7 +814,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.FargateComputeEnvironment", "version": "0.0.0" } }, @@ -990,7 +990,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", "version": "0.0.0" } }, @@ -1274,7 +1274,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", "version": "0.0.0" } }, @@ -1500,7 +1500,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", "version": "0.0.0" } }, @@ -1526,6 +1526,16 @@ "ipProtocol": "-1" } ], + "tags": [ + { + "key": "foo", + "value": "bar" + }, + { + "key": "super", + "value": "salamander" + } + ], "vpcId": { "Ref": "vpcA2121C38" } @@ -1585,6 +1595,16 @@ ] ] } + ], + "tags": [ + { + "key": "foo", + "value": "bar" + }, + { + "key": "super", + "value": "salamander" + } ] } }, @@ -1664,12 +1684,16 @@ } ], "tags": { - "key": "value", - "foo": "bar" + "foo": "bar", + "super": "salamander" } }, "replaceComputeEnvironment": false, "state": "ENABLED", + "tags": { + "foo": "bar", + "super": "salamander" + }, "updatePolicy": {} } }, @@ -1680,7 +1704,7 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.Resource", + "fqn": "@aws-cdk/aws-batch-alpha.ManagedEc2EcsComputeEnvironment", "version": "0.0.0" } }, diff --git a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts index d04a64bb13495..a2976e021f3f6 100644 --- a/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts +++ b/packages/@aws-cdk/aws-batch-alpha/test/integ.managed-compute-environment.ts @@ -1,7 +1,7 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2'; import { LaunchTemplate } from 'aws-cdk-lib/aws-ec2'; import { Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { App, Duration, Stack } from 'aws-cdk-lib'; +import { App, Duration, Stack, Tags } from 'aws-cdk-lib'; import * as integ from '@aws-cdk/integ-tests-alpha'; import { AllocationStrategy, FargateComputeEnvironment, ManagedEc2EcsComputeEnvironment } from '../lib'; @@ -64,12 +64,10 @@ const taggedEc2Ecs = new ManagedEc2EcsComputeEnvironment(stack, 'taggedCE', { images: [{ image: new ec2.AmazonLinuxImage(), }], - instanceTags: { - key: 'value', - }, }); -taggedEc2Ecs.addInstanceTag('foo', 'bar'); +Tags.of(taggedEc2Ecs).add('foo', 'bar'); +Tags.of(taggedEc2Ecs).add('super', 'salamander'); new integ.IntegTest(app, 'BatchManagedComputeEnvironmentTest', { testCases: [stack], 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 c8330a8bb1141..fd7e3fab7df57 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 @@ -2,7 +2,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import * as eks from 'aws-cdk-lib/aws-eks'; import { ArnPrincipal, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam'; -import { Stack, Duration } from 'aws-cdk-lib'; +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'; @@ -565,16 +565,14 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] }); }); - test('respects instanceTags', () => { + test('respects tags', () => { // WHEN const ce = new ComputeEnvironment(stack, 'MyCE', { ...defaultProps, - instanceTags: { - boo: 'bah', - }, }); - ce.addInstanceTag('key', 'value'); + Tags.of(ce).add('superfood', 'acai'); + Tags.of(ce).add('super', 'salamander'); // THEN Template.fromStack(stack).hasResourceProperties('AWS::Batch::ComputeEnvironment', { @@ -582,8 +580,8 @@ describe.each([ManagedEc2EcsComputeEnvironment, ManagedEc2EksComputeEnvironment] ComputeResources: { ...defaultComputeResources, Tags: { - boo: 'bah', - key: 'value', + superfood: 'acai', + super: 'salamander', }, }, });