feat(elasticache): add validation for cache parameter group existence in replication group operations (#2957)

Signed-off-by: Matheus André <matheusandr2@gmail.com>
This commit is contained in:
Matheus André authored and GitHub committed 2026-09-03 17:24:34 -04:00
1 parent df0e7bc79c
commit 6c9cc95d54
5 files changed
+127 -1

No files matched your search

@@ -144,6 +144,9 @@ public class ElastiCacheService implements ResourceProvider {
// resolved with the other validations, before a port is taken or a container started
ReplicationGroupSettings resolvedSettings =
settings.withKmsKeyId(resolveKmsKeyArn(settings.kmsKeyId(), request.region()));
if (request.cacheParameterGroupName() != null && !request.cacheParameterGroupName().isBlank()) {
requireParameterGroup(request.cacheParameterGroupName());
}
if (groups.get(groupId).isPresent()) {
throw new AwsException("ReplicationGroupAlreadyExistsFault",
"Replication group " + groupId + " already exists.", 400);
@@ -1143,11 +1146,22 @@ public class ElastiCacheService implements ResourceProvider {
throw new AwsException("CacheParameterGroupNotFound",
"CacheParameterGroupnot found: " + name, 404);
}
if (isParameterGroupInUse(name)) {
throw new AwsException("InvalidCacheParameterGroupState",
"One or more cache clusters are still members of this parameter group "
+ name + ", so the group cannot be deleted.", 400);
}
parameterGroups.delete(name);
}
LOG.infov("Deleted cache parameter group {0}", name);
}
/** Whether a stored replication group still references the parameter group by that name. */
private boolean isParameterGroupInUse(String name) {
return groups.scan(key -> true).stream()
.anyMatch(group -> name.equals(group.getCacheParameterGroupName()));
}
@Override
public List<ExplorerResource> getResources() {
List<ExplorerResource> resources = new ArrayList<>();