From 20d5c32a96db047bf546f782dc4f4dbf5f6ef756 Mon Sep 17 00:00:00 2001 From: Alvin Kwan Date: Thu, 19 Sep 2024 11:40:51 -0700 Subject: [PATCH 1/4] add tagging parameter for createGlobalCluster --- .../aws-rds-globalcluster.json | 38 ++++++++++++++++++- .../rds/globalcluster/BaseHandlerStd.java | 2 +- .../amazon/rds/globalcluster/Translator.java | 5 ++- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/aws-rds-globalcluster/aws-rds-globalcluster.json b/aws-rds-globalcluster/aws-rds-globalcluster.json index abd295996..6359e93d8 100644 --- a/aws-rds-globalcluster/aws-rds-globalcluster.json +++ b/aws-rds-globalcluster/aws-rds-globalcluster.json @@ -12,6 +12,16 @@ "aurora-postgresql" ] }, + "Tags": { + "type": "array", + "maxItems": 50, + "uniqueItems": true, + "insertionOrder": false, + "description": "An array of key-value pairs to apply to this resource.", + "items": { + "$ref": "#/definitions/Tag" + } + }, "EngineLifecycleSupport": { "description": "The life cycle type of the global cluster. You can use this setting to enroll your global cluster into Amazon RDS Extended Support.", "type": "string" @@ -46,6 +56,30 @@ "type": "boolean" } }, + "definitions": { + "Tag": { + "description": "A key-value pair to associate with a resource.", + "type": "object", + "additionalProperties": false, + "properties": { + "Key": { + "type": "string", + "description": "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -. ", + "minLength": 1, + "maxLength": 128 + }, + "Value": { + "type": "string", + "description": "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -. ", + "minLength": 0, + "maxLength": 256 + } + }, + "required": [ + "Key" + ] + } + }, "oneOf": [ { "required": [ @@ -87,7 +121,9 @@ "update": { "permissions": [ "rds:ModifyGlobalCluster", - "rds:DescribeGlobalClusters" + "rds:DescribeGlobalClusters", + "rds:AddTagsToResource", + "rds:RemoveTagsFromResource" ] }, "delete": { diff --git a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java index f3544bba1..c779c7576 100644 --- a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java +++ b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java @@ -199,7 +199,7 @@ protected ProgressEvent createGlobalClusterWithS .done((describeDbClusterRequest, describeDbClusterResponse, proxyClient2, resourceModel, callbackContext) -> { final String arn = describeDbClusterResponse.dbClusters().get(0).dbClusterArn(); try { - proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn), proxyClient2.client()::createGlobalCluster); + proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn, Tagging.TagSet.emptySet()), proxyClient2.client()::createGlobalCluster); callbackContext.setGlobalClusterCreated(true); } catch (GlobalClusterAlreadyExistsException e) { throw new CfnAlreadyExistsException(e); diff --git a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java index 15c8f7f7c..7bacf3adc 100644 --- a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java +++ b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java @@ -21,10 +21,10 @@ public class Translator { static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model) { - return createGlobalClusterRequest(model, null); + return createGlobalClusterRequest(model, null, Tagging.TagSet.emptySet()); } - static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, String dbClusterArn) { + static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, String dbClusterArn, final Tagging.TagSet tagSet) { return CreateGlobalClusterRequest.builder() .engine(model.getEngine()) .engineVersion(model.getEngineVersion()) @@ -33,6 +33,7 @@ static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel .sourceDBClusterIdentifier(StringUtils.isBlank(dbClusterArn) ? model.getSourceDBClusterIdentifier() : dbClusterArn) .storageEncrypted(model.getStorageEncrypted()) .engineLifecycleSupport(model.getEngineLifecycleSupport()) + .tags(Tagging.translateTagsToSdk(tagSet)) .build(); } From d4603650a56fbbd4e49eae687cdad3c2aa099ff6 Mon Sep 17 00:00:00 2001 From: Alvin Kwan Date: Mon, 28 Oct 2024 14:09:27 -0700 Subject: [PATCH 2/4] update global cluster taggable to be true --- aws-rds-globalcluster/aws-rds-globalcluster.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-rds-globalcluster/aws-rds-globalcluster.json b/aws-rds-globalcluster/aws-rds-globalcluster.json index 6359e93d8..53efb0963 100644 --- a/aws-rds-globalcluster/aws-rds-globalcluster.json +++ b/aws-rds-globalcluster/aws-rds-globalcluster.json @@ -141,6 +141,6 @@ } }, "tagging": { - "taggable": false + "taggable": true } } From 97cc3cf4dc921bba5a38b9a7c83652efcfa7b3e4 Mon Sep 17 00:00:00 2001 From: Alvin Kwan Date: Wed, 27 Nov 2024 11:11:08 -0800 Subject: [PATCH 3/4] update tagging section for rds-global-cluster --- aws-rds-globalcluster/aws-rds-globalcluster.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aws-rds-globalcluster/aws-rds-globalcluster.json b/aws-rds-globalcluster/aws-rds-globalcluster.json index 53efb0963..2b2b5f55c 100644 --- a/aws-rds-globalcluster/aws-rds-globalcluster.json +++ b/aws-rds-globalcluster/aws-rds-globalcluster.json @@ -141,6 +141,14 @@ } }, "tagging": { - "taggable": true + "taggable": true, + "tagOnCreate": true, + "tagUpdatable": true, + "cloudFormationSystemTags": true, + "tagProperty": "/properties/Tags", + "permissions": [ + "rds:AddTagsToResource", + "rds:RemoveTagsFromResource" + ] } } From c66b08e0a4a3c85e3426544d491abf97a8be1fbf Mon Sep 17 00:00:00 2001 From: Alvin Kwan Date: Wed, 27 Nov 2024 11:11:08 -0800 Subject: [PATCH 4/4] add tagging parameter for createGlobalCluster --- .../rds/globalcluster/BaseHandlerStd.java | 8 +++++--- .../amazon/rds/globalcluster/Translator.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java index c779c7576..aeb088d5f 100644 --- a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java +++ b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/BaseHandlerStd.java @@ -188,7 +188,8 @@ protected ProgressEvent removeFromGlobalCluster( protected ProgressEvent createGlobalClusterWithSourceDBCluster(final AmazonWebServicesClientProxy proxy, final ProxyClient proxyClient, - final ProgressEvent progress) { + final ProgressEvent progress, + final Tagging.TagSet tagSet) { if(progress.getCallbackContext().isGlobalClusterCreated()) return progress; //check if sourceDbCluster is not null and is in format of Identifier @@ -199,7 +200,7 @@ protected ProgressEvent createGlobalClusterWithS .done((describeDbClusterRequest, describeDbClusterResponse, proxyClient2, resourceModel, callbackContext) -> { final String arn = describeDbClusterResponse.dbClusters().get(0).dbClusterArn(); try { - proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn, Tagging.TagSet.emptySet()), proxyClient2.client()::createGlobalCluster); + proxyClient2.injectCredentialsAndInvokeV2(Translator.createGlobalClusterRequest(resourceModel, arn, tagSet), proxyClient2.client()::createGlobalCluster); callbackContext.setGlobalClusterCreated(true); } catch (GlobalClusterAlreadyExistsException e) { throw new CfnAlreadyExistsException(e); @@ -210,7 +211,8 @@ protected ProgressEvent createGlobalClusterWithS protected ProgressEvent createGlobalCluster(final AmazonWebServicesClientProxy proxy, final ProxyClient proxyClient, - final ProgressEvent progress) { + final ProgressEvent progress, + final Tagging.TagSet tagSet) { return proxy.initiate("rds::create-global-cluster", proxyClient, progress.getResourceModel(), progress.getCallbackContext()) // request to create global cluster diff --git a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java index 7bacf3adc..2b6df2945 100644 --- a/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java +++ b/aws-rds-globalcluster/src/main/java/software/amazon/rds/globalcluster/Translator.java @@ -20,8 +20,13 @@ public class Translator { +<<<<<<< HEAD static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model) { return createGlobalClusterRequest(model, null, Tagging.TagSet.emptySet()); +======= + static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, final Tagging.TagSet tagSet) { + return createGlobalClusterRequest(model, null, tagSet); +>>>>>>> d618efc (add tagging parameter for createGlobalCluster) } static CreateGlobalClusterRequest createGlobalClusterRequest(final ResourceModel model, String dbClusterArn, final Tagging.TagSet tagSet) { @@ -86,4 +91,16 @@ static DescribeDbClustersRequest describeDbClustersRequest(final ResourceModel m .dbClusterIdentifier(model.getSourceDBClusterIdentifier()) .build(); } + + static Set translateTagsToSdk( + final Collection tags + ) { + return Optional.ofNullable(tags).orElse(Collections.emptySet()) + .stream() + .map(tag -> software.amazon.awssdk.services.rds.model.Tag.builder() + .key(tag.getKey()) + .value(tag.getValue()) + .build()) + .collect(Collectors.toSet()); + } }