fix(redshift): keep tags on new cluster parameter groups and snapshots (#8068)

CreateClusterParameterGroup and CreateClusterSnapshot both take Tags,
but the handler never parsed them, so the new parameter group or
snapshot came back untagged: in the create response, in
DescribeClusterParameterGroups and DescribeClusterSnapshots, and in
DescribeTags on its ARN.

Tags are now parsed (Tags.Tag.N and Tags.member.N) and stored on the
resource, as CreateClusterSubnetGroup already does, and the
ClusterParameterGroup and Snapshot elements carry a Tags list, as AWS
returns them. DeleteCluster's final snapshot and automated snapshots
are still created without tags.
This commit is contained in:
soreavis authored and GitHub committed 2026-11-11 22:56:25 -04:00
1 parent 35bdfdcb3f
commit 07d6674f79
4 files changed
+74 -15

No files matched your search

@@ -185,7 +185,7 @@ public class RedshiftQueryHandler {
case "CreateClusterSnapshot" -> {
String snapshotIdentifier = params.getFirst("SnapshotIdentifier");
String clusterIdentifier = params.getFirst("ClusterIdentifier");
Snapshot snapshot = service.createSnapshot(snapshotIdentifier, clusterIdentifier);
Snapshot snapshot = service.createSnapshot(snapshotIdentifier, clusterIdentifier, parseTags(params));
String xml = new XmlBuilder()
.start("CreateClusterSnapshotResponse")
.start("CreateClusterSnapshotResult")
@@ -304,7 +304,8 @@ public class RedshiftQueryHandler {
String parameterGroupName = params.getFirst("ParameterGroupName");
String parameterGroupFamily = params.getFirst("ParameterGroupFamily");
String description = params.getFirst("Description");
ClusterParameterGroup group = service.createClusterParameterGroup(parameterGroupName, parameterGroupFamily, description);
ClusterParameterGroup group = service.createClusterParameterGroup(parameterGroupName, parameterGroupFamily,
description, parseTags(params));
String xml = new XmlBuilder()
.start("CreateClusterParameterGroupResponse")
.start("CreateClusterParameterGroupResult")
@@ -1327,8 +1328,12 @@ public class RedshiftQueryHandler {
if (snapshot.getKmsKeyId() != null) {
builder.elem("Encrypted", "true").elem("KmsKeyId", snapshot.getKmsKeyId());
}
builder.start("Tags");
for (Map.Entry<String, String> tag : snapshot.getTags().entrySet()) {
builder.start("Tag").elem("Key", tag.getKey()).elem("Value", tag.getValue()).end("Tag");
}
return builder.end("Snapshot").build();
return builder.end("Tags").end("Snapshot").build();
}
private Response clusterResponse(String operation, Cluster cluster) {
@@ -1460,9 +1465,12 @@ public class RedshiftQueryHandler {
.start("ClusterParameterGroup")
.elem("ParameterGroupName", group.getParameterGroupName())
.elem("ParameterGroupFamily", group.getParameterGroupFamily())
.elem("Description", group.getDescription());
return builder.end("ClusterParameterGroup").build();
.elem("Description", group.getDescription())
.start("Tags");
for (Map.Entry<String, String> tag : group.getTags().entrySet()) {
builder.start("Tag").elem("Key", tag.getKey()).elem("Value", tag.getValue()).end("Tag");
}
return builder.end("Tags").end("ClusterParameterGroup").build();
}
private String buildClusterSubnetGroupXml(ClusterSubnetGroup group) {
@@ -1196,7 +1196,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (!"available".equals(cluster.getClusterStatus())) {
throw new AwsException("InvalidClusterState", "Cluster must be available to create a final snapshot", 400);
}
createSnapshot(finalSnapshotIdentifier, identifier, retentionPeriod);
createSnapshot(finalSnapshotIdentifier, identifier, retentionPeriod, null);
}
Cluster removed = mutate(() -> {
@@ -1950,22 +1950,28 @@ public class RedshiftService implements ManagedSecretRotator {
}
public Snapshot createSnapshot(String snapshotIdentifier, String clusterIdentifier) {
return withResourceLock("cluster", clusterIdentifier, () -> withResourceLock("snapshot", snapshotIdentifier,
() -> createSnapshot(snapshotIdentifier, clusterIdentifier, null)));
return createSnapshot(snapshotIdentifier, clusterIdentifier, null);
}
private Snapshot createSnapshot(String snapshotIdentifier, String clusterIdentifier, Integer retentionPeriod) {
public Snapshot createSnapshot(String snapshotIdentifier, String clusterIdentifier, Map<String, String> tags) {
return withResourceLock("cluster", clusterIdentifier, () -> withResourceLock("snapshot", snapshotIdentifier,
() -> createSnapshot(snapshotIdentifier, clusterIdentifier, null, tags)));
}
private Snapshot createSnapshot(String snapshotIdentifier, String clusterIdentifier, Integer retentionPeriod,
Map<String, String> tags) {
validateSnapshotIdentifier(snapshotIdentifier);
Optional<Cluster> clusterOpt = clusters.get(clusterIdentifier);
if (clusterOpt.isEmpty()) {
throw new AwsException("ClusterNotFound", "Cluster " + clusterIdentifier + " not found", 404);
}
return createSnapshot(clusters.accountId(), snapshotIdentifier, clusterOpt.get(), retentionPeriod,
Instant.now(), null);
Instant.now(), null, tags);
}
private Snapshot createSnapshot(String accountId, String snapshotIdentifier, Cluster cluster,
Integer retentionPeriod, Instant now, Instant scheduledTime) {
Integer retentionPeriod, Instant now, Instant scheduledTime,
Map<String, String> tags) {
rejectPausedCluster(cluster);
validateSnapshotIdentifier(snapshotIdentifier);
String clusterIdentifier = cluster.getClusterIdentifier();
@@ -1990,6 +1996,9 @@ public class RedshiftService implements ManagedSecretRotator {
snapshot.setSnapshotType(scheduledTime == null ? "manual" : "automated");
snapshot.setScheduledTime(scheduledTime);
snapshot.setClusterGeneration(cluster.getSnapshotGeneration());
if (tags != null) {
snapshot.setTags(new LinkedHashMap<>(tags));
}
if (scheduledTime != null) {
snapshot.setAutomatedSnapshotRetentionPeriod(cluster.getAutomatedSnapshotRetentionPeriod());
}
@@ -2444,6 +2453,11 @@ public class RedshiftService implements ManagedSecretRotator {
// ── Parameter Group Operations ───────────────────────────────────────────
public ClusterParameterGroup createClusterParameterGroup(String parameterGroupName, String parameterGroupFamily, String description) {
return createClusterParameterGroup(parameterGroupName, parameterGroupFamily, description, null);
}
public ClusterParameterGroup createClusterParameterGroup(String parameterGroupName, String parameterGroupFamily,
String description, Map<String, String> tags) {
if (DEFAULT_PARAMETER_GROUP_NAME.equals(parameterGroupName)) {
throw new AwsException("InvalidParameterValue", "The default parameter group name is reserved.", 400);
}
@@ -2452,6 +2466,9 @@ public class RedshiftService implements ManagedSecretRotator {
}
ClusterParameterGroup group = new ClusterParameterGroup(parameterGroupName, parameterGroupFamily, description);
if (tags != null) {
group.setTags(new LinkedHashMap<>(tags));
}
parameterGroups.put(parameterGroupName, group);
parameterGroups.flush();
emitEvent(RedshiftEventCatalog.PARAMETER_GROUP_CREATED, parameterGroupName,
@@ -3176,7 +3193,7 @@ public class RedshiftService implements ManagedSecretRotator {
if (tooSoon) {
return false;
}
createSnapshot(accountId, snapshotId, cluster, null, now, scheduled);
createSnapshot(accountId, snapshotId, cluster, null, now, scheduled, null);
} else if (!"automated".equals(existing.getSnapshotType())
|| !clusterId.equals(existing.getClusterIdentifier()) || !scheduled.equals(existing.getScheduledTime())) {
throw new AwsException("ClusterSnapshotAlreadyExists", "Snapshot identifier is already in use", 400);