mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): tag Redshift clusters and parameter groups by ARN, and keep a subnet group's Tags (#9240)
This commit is contained in:
1 parent
3c4efe43bf
commit
bc3a7aaaaf
5 files changed
+220
-69
No files matched your search
+25
-14
@@ -8,6 +8,7 @@ import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.redshift.RedshiftService;
|
||||
import io.floci.aws.services.redshift.model.Cluster;
|
||||
import io.floci.aws.services.redshift.model.ClusterParameterGroup;
|
||||
import io.floci.aws.services.redshift.model.ClusterSubnetGroup;
|
||||
import io.floci.aws.services.redshift.model.Parameter;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -193,15 +194,13 @@ public class RedshiftClusterCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
Map<String, String> tags = ctx.resolveTags(props, "Tags");
|
||||
if (!tags.isEmpty()) {
|
||||
try {
|
||||
redshiftService.createTags(id, tags);
|
||||
} catch (RuntimeException failure) {
|
||||
if (snapshotIdentifier != null && !ctx.reusesPriorEntity(id)) {
|
||||
cleanupRestoredCluster(id, failure);
|
||||
}
|
||||
throw failure;
|
||||
try {
|
||||
reconcileTags(redshiftService.clusterArn(id), cluster.getTags(), tags);
|
||||
} catch (RuntimeException failure) {
|
||||
if (snapshotIdentifier != null && !ctx.reusesPriorEntity(id)) {
|
||||
cleanupRestoredCluster(id, failure);
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
|
||||
r.setPhysicalId(id);
|
||||
@@ -300,14 +299,24 @@ public class RedshiftClusterCfnProvisioner implements CfnResourceProvisioner {
|
||||
redshiftService.modifyClusterParameterGroup(id, parameters);
|
||||
}
|
||||
|
||||
Map<String, String> tags = ctx.resolveTags(props, "Tags");
|
||||
if (!tags.isEmpty()) {
|
||||
redshiftService.createTags(id, tags);
|
||||
}
|
||||
reconcileTags(redshiftService.parameterGroupArn(id),
|
||||
redshiftService.getClusterParameterGroup(id).map(ClusterParameterGroup::getTags).orElse(null),
|
||||
ctx.resolveTags(props, "Tags"));
|
||||
|
||||
r.setPhysicalId(id);
|
||||
}
|
||||
|
||||
/** Drives the stored tags to the template's, since CreateTags alone never removes a key. */
|
||||
private void reconcileTags(String resourceArn, Map<String, String> current, Map<String, String> desired) {
|
||||
List<String> stale = ProvisionContext.staleTagKeys(current, desired);
|
||||
if (!stale.isEmpty()) {
|
||||
redshiftService.deleteTags(resourceArn, stale);
|
||||
}
|
||||
if (!desired.isEmpty()) {
|
||||
redshiftService.createTags(resourceArn, desired);
|
||||
}
|
||||
}
|
||||
|
||||
private ClusterParameterGroup findExistingParameterGroup(String parameterGroupName) {
|
||||
if (parameterGroupName == null || parameterGroupName.isBlank()) {
|
||||
return null;
|
||||
@@ -336,11 +345,13 @@ public class RedshiftClusterCfnProvisioner implements CfnResourceProvisioner {
|
||||
String id = ctx.stablePhysicalName(explicitName, r.getLogicalId(), METADATA_NAME_MAX_LENGTH, false);
|
||||
String description = ctx.resolveOptional(props, "Description");
|
||||
List<String> subnetIds = ctx.resolveStringList(props, "SubnetIds");
|
||||
Map<String, String> tags = ctx.resolveTags(props, "Tags");
|
||||
|
||||
if (ctx.reusesPriorEntity(id)) {
|
||||
redshiftService.modifyClusterSubnetGroup(id, description, subnetIds);
|
||||
ClusterSubnetGroup group = redshiftService.modifyClusterSubnetGroup(id, description, subnetIds);
|
||||
reconcileTags(redshiftService.subnetGroupArn(id), group.getTags(), tags);
|
||||
} else {
|
||||
redshiftService.createClusterSubnetGroup(id, description, null, subnetIds);
|
||||
redshiftService.createClusterSubnetGroup(id, description, null, subnetIds, tags);
|
||||
}
|
||||
|
||||
r.setPhysicalId(id);
|
||||
|
||||
@@ -4284,7 +4284,8 @@ public class RedshiftService implements ManagedSecretRotator {
|
||||
return resource.substring(0, sep);
|
||||
}
|
||||
|
||||
private String clusterArn(String clusterIdentifier) {
|
||||
/** The ARN of a cluster of the request's account and Region, as Redshift's tag calls take it. */
|
||||
public String clusterArn(String clusterIdentifier) {
|
||||
return regionResolver.buildArn("redshift", regionResolver.getRegion(), "cluster:" + clusterIdentifier);
|
||||
}
|
||||
|
||||
@@ -4293,11 +4294,13 @@ public class RedshiftService implements ManagedSecretRotator {
|
||||
"snapshot:" + clusterIdentifier + "/" + snapshotIdentifier);
|
||||
}
|
||||
|
||||
private String parameterGroupArn(String parameterGroupName) {
|
||||
/** The ARN of a cluster parameter group of the request's account and Region, as the tag calls take it. */
|
||||
public String parameterGroupArn(String parameterGroupName) {
|
||||
return regionResolver.buildArn("redshift", regionResolver.getRegion(), "parametergroup:" + parameterGroupName);
|
||||
}
|
||||
|
||||
private String subnetGroupArn(String name) {
|
||||
/** The ARN of a cluster subnet group of the request's account and Region, as the tag calls take it. */
|
||||
public String subnetGroupArn(String name) {
|
||||
return regionResolver.buildArn("redshift", regionResolver.getRegion(), "subnetgroup:" + name);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user