From 304f5b6974f1121a8a5ff802076dffe2eff9f407 Mon Sep 17 00:00:00 2001 From: Choryu Park Date: Mon, 10 Jan 2022 22:00:31 +0900 Subject: [PATCH] feat(eks): cluster tagging (#4995) (#18109) Fixes #4995 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-eks/lib/cluster-resource.ts | 2 ++ packages/@aws-cdk/aws-eks/lib/cluster.ts | 9 ++++++++- .../aws-eks/test/integ.eks-cluster.expected.json | 3 +++ packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts | 3 +++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-eks/lib/cluster-resource.ts b/packages/@aws-cdk/aws-eks/lib/cluster-resource.ts index ed0852338a527..6a947380e3dd1 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster-resource.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster-resource.ts @@ -28,6 +28,7 @@ export interface ClusterResourceProps { readonly secretsEncryptionKey?: kms.IKey; readonly onEventLayer?: lambda.ILayerVersion; readonly clusterHandlerSecurityGroup?: ec2.ISecurityGroup; + readonly tags?: { [key: string]: string }; } /** @@ -89,6 +90,7 @@ export class ClusterResource extends CoreConstruct { endpointPrivateAccess: props.endpointPrivateAccess, publicAccessCidrs: props.publicAccessCidrs, }, + tags: props.tags, }, AssumeRoleArn: this.adminRole.roleArn, diff --git a/packages/@aws-cdk/aws-eks/lib/cluster.ts b/packages/@aws-cdk/aws-eks/lib/cluster.ts index 2b917f8f93f7e..10a3f2123aac1 100644 --- a/packages/@aws-cdk/aws-eks/lib/cluster.ts +++ b/packages/@aws-cdk/aws-eks/lib/cluster.ts @@ -744,13 +744,19 @@ export interface ClusterProps extends ClusterOptions { */ readonly defaultCapacityType?: DefaultCapacityType; - /** * The IAM role to pass to the Kubectl Lambda Handler. * * @default - Default Lambda IAM Execution Role */ readonly kubectlLambdaRole?: iam.IRole; + + /** + * The tags assigned to the EKS cluster + * + * @default - none + */ + readonly tags?: { [key: string]: string }; } /** @@ -1372,6 +1378,7 @@ export class Cluster extends ClusterBase { subnets: placeClusterHandlerInVpc ? privateSubnets : undefined, clusterHandlerSecurityGroup: this.clusterHandlerSecurityGroup, onEventLayer: this.onEventLayer, + tags: props.tags, }); if (this.endpointAccess._config.privateAccess && privateSubnets.length !== 0) { diff --git a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json index 00ab6f9f6fe3c..7b5af8f848f2e 100644 --- a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json +++ b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.expected.json @@ -951,6 +951,9 @@ ], "endpointPublicAccess": true, "endpointPrivateAccess": true + }, + "tags": { + "foo": "bar" } }, "AssumeRoleArn": { diff --git a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts index 5cbc0e384eb17..8dd012b3e2d66 100644 --- a/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts +++ b/packages/@aws-cdk/aws-eks/test/integ.eks-cluster.ts @@ -38,6 +38,9 @@ class EksClusterStack extends TestStack { defaultCapacity: 2, version: eks.KubernetesVersion.V1_21, secretsEncryptionKey, + tags: { + foo: 'bar', + }, }); this.assertFargateProfile();