This repository was archived by the owner on Oct 23, 2025. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 16
 
Tags support added for cluster subnet group #187
          
     Open
      
      
            pmugdhamz
  wants to merge
  3
  commits into
  aws-cloudformation:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
pmugdhamz:clustersubnetgroup-3
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "desiredResourceState": { | ||
| "ClusterSubnetGroupName": "cfn-subnet-group-4", | ||
| "Description": "Test Subnet Group Description", | ||
| "SubnetIds": [ | ||
| "subnet-0ddbac69e73569727", | ||
| "subnet-0d1b9f96842cb5777" | ||
| ], | ||
| "Tags": [ | ||
| { | ||
| "Key": "Environment", | ||
| "Value": "Test" | ||
| } | ||
| ] | ||
| }, | ||
| "previousResourceState": null, | ||
| "logicalResourceIdentifier": "MySubnetGroup", | ||
| "clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "desiredResourceState": { | ||
| "ClusterSubnetGroupName": "cfn-subnet-group-1" | ||
| }, | ||
| "previousResourceState": null, | ||
| "logicalResourceIdentifier": "cfn-subnet-group-1", | ||
| "clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "desiredResourceState": {}, | ||
| "previousResourceState": null, | ||
| "nextToken": null, | ||
| "logicalResourceIdentifier": "cfn-subnet-group-4", | ||
| "clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "desiredResourceState": { | ||
| "ClusterSubnetGroupName": "cfn-subnet-group-4" | ||
| }, | ||
| "previousResourceState": null, | ||
| "logicalResourceIdentifier": "cfn-subnet-group-4", | ||
| "clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "desiredResourceState": { | ||
| "ClusterSubnetGroupName": "cfn-subnet-group-4", | ||
| "Description": "Updated Subnet Group Description", | ||
| "SubnetIds": [ | ||
| "subnet-0d1b9f96842cb5777" | ||
| ], | ||
| "Tags": [ | ||
| { | ||
| "Key": "Environment", | ||
| "Value": "Production" | ||
| } | ||
| ] | ||
| }, | ||
| "previousResourceState": { | ||
| "ClusterSubnetGroupName": "cfn-subnet-group-4", | ||
| "Description": "Test Subnet Group Description", | ||
| "SubnetIds": [ | ||
| "subnet-0ddbac69e73569727", | ||
| "subnet-0d1b9f96842cb5777" | ||
| ], | ||
| "Tags": [ | ||
| { | ||
| "Key": "Environment", | ||
| "Value": "Test" | ||
| } | ||
| ] | ||
| }, | ||
| "logicalResourceIdentifier": "MySubnetGroup", | ||
| "clientRequestToken": "4b90a7e4-b790-456b-a937-0cfdfa211dfe" | ||
| } | 
        
          
          
            87 changes: 71 additions & 16 deletions
          
          87 
        
  ...subnetgroup/src/main/java/software/amazon/redshift/clustersubnetgroup/BaseHandlerStd.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,33 +1,88 @@ | ||
| package software.amazon.redshift.clustersubnetgroup; | ||
| 
     | 
||
| import com.amazonaws.util.StringUtils; | ||
| import software.amazon.awssdk.services.redshift.RedshiftClient; | ||
| import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; | ||
| import software.amazon.cloudformation.proxy.Logger; | ||
| import software.amazon.cloudformation.proxy.HandlerErrorCode; | ||
| import software.amazon.cloudformation.proxy.ProgressEvent; | ||
| import software.amazon.cloudformation.proxy.ProxyClient; | ||
| import software.amazon.cloudformation.proxy.ResourceHandlerRequest; | ||
| 
     | 
||
| import software.amazon.awssdk.services.redshift.model.DescribeTagsRequest; | ||
| import software.amazon.awssdk.services.redshift.model.DescribeTagsResponse; | ||
| import software.amazon.awssdk.services.redshift.model.CreateTagsResponse; | ||
| import software.amazon.awssdk.services.redshift.model.InvalidTagException; | ||
| import software.amazon.awssdk.services.redshift.model.InvalidClusterStateException; | ||
| import software.amazon.awssdk.services.redshift.model.ResourceNotFoundException; | ||
| 
     | 
||
| public abstract class BaseHandlerStd extends BaseHandler<CallbackContext> { | ||
| protected Logger logger; | ||
| protected static final String CALL_GRAPH_TYPE_NAME = StringUtils.replace(ResourceModel.TYPE_NAME, "::", "-"); | ||
| 
     | 
||
| @Override | ||
| public final ProgressEvent<ResourceModel, CallbackContext> handleRequest( | ||
| final AmazonWebServicesClientProxy proxy, | ||
| final ResourceHandlerRequest<ResourceModel> request, | ||
| final CallbackContext callbackContext, | ||
| final Logger logger) { | ||
| final AmazonWebServicesClientProxy proxy, | ||
| final ResourceHandlerRequest<ResourceModel> request, | ||
| final CallbackContext callbackContext, | ||
| final Logger logger) { | ||
| return handleRequest( | ||
| proxy, | ||
| request, | ||
| callbackContext != null ? callbackContext : new CallbackContext(), | ||
| proxy.newProxy(ClientBuilder::getClient), | ||
| logger | ||
| proxy, | ||
| request, | ||
| callbackContext != null ? callbackContext : new CallbackContext(), | ||
| proxy.newProxy(ClientBuilder::getClient), | ||
| logger | ||
| ); | ||
| } | ||
| 
     | 
||
| protected abstract ProgressEvent<ResourceModel, CallbackContext> handleRequest( | ||
| final AmazonWebServicesClientProxy proxy, | ||
| final ResourceHandlerRequest<ResourceModel> request, | ||
| final CallbackContext callbackContext, | ||
| final ProxyClient<RedshiftClient> proxyClient, | ||
| final Logger logger); | ||
| } | ||
| final AmazonWebServicesClientProxy proxy, | ||
| final ResourceHandlerRequest<ResourceModel> request, | ||
| final CallbackContext callbackContext, | ||
| final ProxyClient<RedshiftClient> proxyClient, | ||
| final Logger logger); | ||
| 
     | 
||
| protected DescribeTagsResponse readTags(final DescribeTagsRequest awsRequest, | ||
| final ProxyClient<RedshiftClient> proxyClient) { | ||
| DescribeTagsResponse awsResponse; | ||
| awsResponse = proxyClient.injectCredentialsAndInvokeV2(awsRequest, proxyClient.client()::describeTags); | ||
| logger.log(awsResponse.toString()); | ||
| logger.log(String.format("%s's tags have successfully been read.", ResourceModel.TYPE_NAME)); | ||
| return awsResponse; | ||
| } | ||
| 
     | 
||
| protected CreateTagsResponse updateTags(final ModifyTagsRequest awsRequest, | ||
| final ProxyClient<RedshiftClient> proxyClient) { | ||
| CreateTagsResponse awsResponse = null; | ||
| 
     | 
||
| if (awsRequest.getDeleteOldTagsRequest().tagKeys().isEmpty()) { | ||
| logger.log(String.format("No tags would be deleted for the resource: %s.", ResourceModel.TYPE_NAME)); | ||
| } else { | ||
| proxyClient.injectCredentialsAndInvokeV2(awsRequest.getDeleteOldTagsRequest(), proxyClient.client()::deleteTags); | ||
| logger.log(String.format("Delete tags for the resource: %s.", ResourceModel.TYPE_NAME)); | ||
| } | ||
| 
     | 
||
| if (awsRequest.getCreateNewTagsRequest().tags().isEmpty()) { | ||
| logger.log(String.format("No tags would be created for the resource: %s.", ResourceModel.TYPE_NAME)); | ||
| } else { | ||
| awsResponse = proxyClient.injectCredentialsAndInvokeV2(awsRequest.getCreateNewTagsRequest(), proxyClient.client()::createTags); | ||
| logger.log(String.format("Create tags for the resource: %s.", ResourceModel.TYPE_NAME)); | ||
| } | ||
| 
     | 
||
| return awsResponse; | ||
| } | ||
| 
     | 
||
| protected ProgressEvent<ResourceModel, CallbackContext> operateTagsErrorHandler(final Object awsRequest, | ||
| final Exception exception, | ||
| final ProxyClient<RedshiftClient> client, | ||
| final ResourceModel model, | ||
| final CallbackContext context) { | ||
| if (exception instanceof ResourceNotFoundException) { | ||
| return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.NotFound); | ||
| } else if (exception instanceof InvalidTagException || | ||
| exception instanceof InvalidClusterStateException) { | ||
| return ProgressEvent.defaultFailureHandler(exception, HandlerErrorCode.InvalidRequest); | ||
| } else { | ||
| return ProgressEvent.failed(model, context, HandlerErrorCode.UnauthorizedTaggingOperation, exception.getMessage()); | ||
| } | ||
| } | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get rid of these SAM files, if not needed.