mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 02:28:08 -05:00
fix(cloudformation): ElastiCache subnet group, user and user group replace on the engine's decision (#10090)
ElastiCache SubnetGroup, User and UserGroup take replacement from the engine's NamedChange, as the types in #9671 do, and leave change-exempt.tsv. A subnet group whose CacheSubnetGroupName is removed is now replaced rather than updated in place under its old name, and a UserName change under the same UserId fails with CloudFormation's custom-named replacement error instead of InvalidParameterValue. Part of #6606.
This commit is contained in:
1 parent
1afba75712
commit
b95c6b21e2
4 files changed
+36
-15
No files matched your search
+18
-6
@@ -4,6 +4,7 @@ import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.JacksonConfig;
|
||||
import io.floci.aws.core.common.JsonNodes;
|
||||
import io.floci.aws.services.cloudformation.model.StackResource;
|
||||
import io.floci.aws.services.cloudformation.provisioners.ProvisionContext.NamedChange;
|
||||
import io.floci.aws.services.elasticache.ElastiCacheMemcachedService;
|
||||
import io.floci.aws.services.elasticache.ElastiCacheService;
|
||||
import io.floci.aws.services.elasticache.UserAuthentication;
|
||||
@@ -28,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
/**
|
||||
* Provisions AWS::ElastiCache::CacheCluster, ReplicationGroup, SubnetGroup, User and UserGroup. A cache cluster needs
|
||||
@@ -482,11 +484,13 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
throw new AwsException("ValidationException",
|
||||
"CacheSubnetGroupName exceeds maximum length of " + SUBNET_GROUP_NAME_MAX_LENGTH, 400);
|
||||
}
|
||||
String id = ctx.stablePhysicalName(explicitName, r.getLogicalId(), SUBNET_GROUP_NAME_MAX_LENGTH, true);
|
||||
NamedChange change = ctx.changes(SUBNET_GROUP, props, explicitName, r.getLogicalId(),
|
||||
SUBNET_GROUP_NAME_MAX_LENGTH, true, UnaryOperator.identity());
|
||||
String id = change.name();
|
||||
List<String> subnetIds = ctx.resolveStringList(props, "SubnetIds");
|
||||
|
||||
CacheSubnetGroup group;
|
||||
if (ctx.reusesPriorEntity(id)) {
|
||||
if (ctx.isUpdate() && !change.replaces()) {
|
||||
List<CacheSubnetGroup> existing = elastiCacheService.describeCacheSubnetGroups(id);
|
||||
if (!existing.isEmpty()) {
|
||||
CacheSubnetGroup prior = existing.getFirst();
|
||||
@@ -524,12 +528,16 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
LOG.warnv("ElastiCache user {0}: Tags are ignored, the emulator does not tag users", userId);
|
||||
}
|
||||
|
||||
// UserName is create-only; the engine refuses its change under the same UserId.
|
||||
NamedChange change = ctx.changes(USER, props, userId, r.getLogicalId(), 0, false,
|
||||
UnaryOperator.identity());
|
||||
userId = change.name();
|
||||
ElastiCacheUser user;
|
||||
if (ctx.reusesPriorEntity(userId)) {
|
||||
if (ctx.isUpdate() && !change.replaces()) {
|
||||
ElastiCacheUser existing = elastiCacheService.getUser(userId);
|
||||
// The stored user is checked too, for an update where the engine had no prior values to compare.
|
||||
if (!userName.equals(existing.getUserName())) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"UserName of user " + userId + " is create-only; use a new UserId to change it", 400);
|
||||
throw CfnExceptions.customNamedReplacement(userId);
|
||||
}
|
||||
UserSnapshot snapshot = new UserSnapshot(
|
||||
existing.getUserId(),
|
||||
@@ -572,8 +580,12 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
LOG.warnv("ElastiCache user group {0}: Tags are ignored, the emulator does not tag user groups", groupId);
|
||||
}
|
||||
|
||||
// The service stores the id in lowercase, so the prior physical id only matches in that form.
|
||||
NamedChange change = ctx.changes(USER_GROUP, props, groupId, r.getLogicalId(), 0, true,
|
||||
s -> s.toLowerCase(Locale.ROOT));
|
||||
groupId = change.name();
|
||||
ElastiCacheUserGroup group;
|
||||
if (ctx.reusesPriorEntity(groupId)) {
|
||||
if (ctx.isUpdate() && !change.replaces()) {
|
||||
ElastiCacheUserGroup existing = elastiCacheService.getUserGroup(groupId);
|
||||
UserGroupSnapshot snapshot = new UserGroupSnapshot(
|
||||
existing.getUserGroupId(),
|
||||
|
||||
@@ -178,6 +178,12 @@ class CfnReplacementIntegrationTest {
|
||||
+ " \"HostedZoneConfig\": {\"Comment\": \"second\"}",
|
||||
"False", false, null),
|
||||
SUBNET_GROUP_REPLACED,
|
||||
createOnlyRow("ElastiCache subnet group CacheSubnetGroupName removed",
|
||||
json(vpcAndSubnet("10.74")).replaceAll(",$", ""), "", "AWS::ElastiCache::SubnetGroup",
|
||||
"\"CacheSubnetGroupName\": \"repl-sng-named\", \"Description\": \"example\","
|
||||
+ " \"SubnetIds\": [{\"Ref\": \"Subnet\"}]",
|
||||
"\"Description\": \"example\", \"SubnetIds\": [{\"Ref\": \"Subnet\"}]",
|
||||
"True", false, null),
|
||||
createOnlyRow("SQS queue explicit QueueName removed", "", "", SQS_TYPE,
|
||||
"\"QueueName\": \"repl-q-removed\"", "\"VisibilityTimeout\": 30", "True", false, null),
|
||||
new Row("SQS queue QueueName dropped by Fn::If choosing AWS::NoValue, beside an updatable change",
|
||||
|
||||
+12
-6
@@ -639,15 +639,21 @@ class ElastiCacheCfnProvisionerTest {
|
||||
verify(cache).setUserGroupMembers(eq("team"), eq(List.of("d", "new")), eq("redis"));
|
||||
}
|
||||
|
||||
/** UserName is "Update requires: Replacement", and a custom-named replacement under the same UserId is refused. */
|
||||
@Test
|
||||
void userNameChangeIsRejectedBecauseItIsCreateOnly() throws Exception {
|
||||
ElastiCacheUser existing = new ElastiCacheUser("app", "old-name", AuthMode.NO_AUTH, List.of(), "on ~* +@all",
|
||||
"redis", "active", Instant.now());
|
||||
when(cache.getUser("app")).thenReturn(existing);
|
||||
void userNameChangeUnderTheSameUserIdIsRefusedAsACustomNamedReplacement() throws Exception {
|
||||
when(cache.getUser("app")).thenReturn(new ElastiCacheUser("app", "old-name", AuthMode.NO_AUTH, List.of(),
|
||||
"on ~* +@all", "redis", "active", Instant.now()));
|
||||
StackResource r = resource("AWS::ElastiCache::User", "AppUser");
|
||||
ObjectNode renamed = props("{\"UserId\":\"app\",\"UserName\":\"new-name\",\"Engine\":\"redis\"}");
|
||||
ProvisionContext update = ctx("app", "{\"UserId\":\"app\",\"UserName\":\"old-name\",\"Engine\":\"redis\"}");
|
||||
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r,
|
||||
props("{\"UserId\":\"app\",\"UserName\":\"new-name\",\"Engine\":\"redis\"}"), ctx("app")));
|
||||
for (ProvisionContext context : List.of(update, ctx("app"))) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> provisioner.provision(r, renamed, context));
|
||||
|
||||
assertEquals("ValidationError", e.getErrorCode());
|
||||
assertTrue(e.getMessage().contains("custom-named"), e.getMessage());
|
||||
}
|
||||
verify(cache, never()).modifyUser(any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
|
||||
@@ -81,9 +81,6 @@ AWS::EFS::AccessPoint update not yet on the engine's changes (#6606)
|
||||
AWS::EFS::FileSystem update not yet on the engine's changes (#6606)
|
||||
AWS::EFS::MountTarget update not yet on the engine's changes (#6606)
|
||||
AWS::ElastiCache::ServerlessCache prior entity found by reusesPriorEntity; moves to the engine's decision with the create-only work
|
||||
AWS::ElastiCache::SubnetGroup prior entity found by reusesPriorEntity; moves to the engine's decision with the create-only work
|
||||
AWS::ElastiCache::User prior entity found by reusesPriorEntity; moves to the engine's decision with the create-only work
|
||||
AWS::ElastiCache::UserGroup prior entity found by reusesPriorEntity; moves to the engine's decision with the create-only work
|
||||
AWS::ElasticLoadBalancingV2::Listener update not yet on the engine's changes (#6606)
|
||||
AWS::ElasticLoadBalancingV2::ListenerCertificate update not yet on the engine's changes (#6606)
|
||||
AWS::ElasticLoadBalancingV2::ListenerRule update not yet on the engine's changes (#6606)
|
||||
|
||||
|
Reference in new issue
Block a user