mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(cloudformation): provision ElastiCache replication groups (#8448)
CloudFormation now provisions AWS::ElastiCache::ReplicationGroup instead of completing the stack with no cache behind it. The group is created through the ElastiCache service, Ref returns its id, and Fn::GetAtt exposes the configuration endpoint for a cluster-mode group or the primary, reader and per-node read endpoints otherwise. A create-only change replaces the group, an explicit ReplicationGroupId that stays the same is refused, and an update that reuses the group warns only about the properties it ignores. Optional booleans in the ElastiCache, IoT authorizer, API Gateway API key and StackSet provisioners are read through ProvisionContext.resolveOptionalBoolean, which refuses a value that is neither true nor false instead of reading it as false. Closes #8447
This commit is contained in:
1 parent
3fa20af859
commit
9e05c07bfc
16 files changed
+512
-34
No files matched your search
@@ -222,7 +222,7 @@ cross-resource references.
|
||||
| EKS | `Cluster`, `Nodegroup` |
|
||||
| RDS | `DBInstance` (starts a real container), `DBCluster` (starts a real container), `DBSubnetGroup`, `DBParameterGroup`, `DBClusterParameterGroup`, `DBProxy`, `DBProxyTargetGroup` |
|
||||
| Aurora DSQL | `Cluster` |
|
||||
| ElastiCache | `CacheCluster` (starts a real container; modifying an existing cluster in place is not supported), `SubnetGroup`, `User` (Tags are ignored), `UserGroup` (Tags are ignored), `ServerlessCache` (GetAtt uses the dotted Endpoint.* and ReaderEndpoint.* form) |
|
||||
| ElastiCache | `CacheCluster` (starts a real container; modifying an existing cluster in place is not supported), `ReplicationGroup` (starts a real container; modifying an existing group in place is not supported), `SubnetGroup`, `User` (Tags are ignored), `UserGroup` (Tags are ignored), `ServerlessCache` (GetAtt uses the dotted Endpoint.* and ReaderEndpoint.* form) |
|
||||
| Redshift | `Cluster` (single-node container; Port and non-dev DBName ignored; ManageMasterPassword unsupported), `ClusterParameterGroup`, `ClusterSubnetGroup`, `ClusterSecurityGroup` (accepted; no EC2-Classic security group model), `EventSubscription` |
|
||||
| Redshift Serverless | `Namespace` (Managed admin credentials use Secrets Manager; GetAtt uses the dotted Namespace.* form), `Workgroup` (starts a real container; one workgroup per namespace; capacity, VPC and price-performance settings are stored only; snapshot restore properties are ignored; GetAtt uses the dotted Workgroup.* form) |
|
||||
| EC2 | `VPC` (`Tags` update in place, keeping tags added outside the stack; deleted on stack teardown; a VPC with dependents outside the stack, including anything still holding a network interface in its subnets (an instance that is not terminated, a NAT gateway that is not deleted or failed, a standalone interface, an interface endpoint), fails the delete with `DependencyViolation`, as on AWS), `Subnet`, `SecurityGroup` (inline `SecurityGroupIngress`/`SecurityGroupEgress` supported; `Tags` update in place, keeping tags added outside the stack; a failed stack update puts the rules and tags of a group it changed in place back), `SecurityGroupIngress`, `SecurityGroupEgress`, `InternetGateway`, `RouteTable`, `SubnetRouteTableAssociation`, `Route`, `NatGateway` (zonal; `AvailabilityMode` regional fails; a change to the `Secondary*` address properties updates the gateway in place), `EIP`, `Instance` (`Tags` update in place, keeping tags added outside the stack), `LaunchTemplate`, `VPCGatewayAttachment`, `VPCEndpoint`, `NetworkAcl`, `NetworkAclEntry`, `SubnetNetworkAclAssociation`, `FlowLog` (`Tags` are applied and updated in place, keeping tags added outside the stack; any other change fails, since it needs a replacement), `KeyPair` (a created key's private key is stored in the `SecureString` parameter `/ec2/keypair/<KeyPairId>`, as on AWS, and deleted with the key), `PrefixList` (updated in place; an update that changes `AddressFamily`, or `MaxEntries` together with `Entries`, fails) |
|
||||
|
||||
+4
-9
@@ -82,11 +82,11 @@ public class ApiGatewayApiKeyCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (customerId != null && !customerId.isBlank()) {
|
||||
request.put("customerId", customerId);
|
||||
}
|
||||
Boolean enabled = resolveBoolean(props, "Enabled", ctx);
|
||||
Boolean enabled = ctx.resolveOptionalBoolean(props, "Enabled");
|
||||
if (enabled != null) {
|
||||
request.put("enabled", enabled);
|
||||
}
|
||||
Boolean generateDistinctId = resolveBoolean(props, "GenerateDistinctId", ctx);
|
||||
Boolean generateDistinctId = ctx.resolveOptionalBoolean(props, "GenerateDistinctId");
|
||||
if (generateDistinctId != null) {
|
||||
request.put("generateDistinctId", generateDistinctId);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ApiGatewayApiKeyCfnProvisioner implements CfnResourceProvisioner {
|
||||
if (value != null && !value.isBlank()) {
|
||||
rejectIfChanged("Value", existing.getValue(), value);
|
||||
}
|
||||
Boolean requestedDistinct = resolveBoolean(props, "GenerateDistinctId", ctx);
|
||||
Boolean requestedDistinct = ctx.resolveOptionalBoolean(props, "GenerateDistinctId");
|
||||
if (requestedDistinct != null) {
|
||||
boolean existingDistinct = !Objects.equals(existing.getId(), existing.getValue());
|
||||
if (requestedDistinct != existingDistinct) {
|
||||
@@ -119,7 +119,7 @@ public class ApiGatewayApiKeyCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
// Enabled defaults to false when the template omits it, as in the AWS registry schema.
|
||||
Boolean enabled = resolveBoolean(props, "Enabled", ctx);
|
||||
Boolean enabled = ctx.resolveOptionalBoolean(props, "Enabled");
|
||||
List<Map<String, String>> patches = patchesTo(existing, ctx.resolveOptional(props, "CustomerId"),
|
||||
ctx.resolveOptional(props, "Description"), enabled != null && enabled);
|
||||
Map<String, String> desiredTags = ctx.resolveTags(props, "Tags");
|
||||
@@ -182,11 +182,6 @@ public class ApiGatewayApiKeyCfnProvisioner implements CfnResourceProvisioner {
|
||||
r.getAttributes().put("APIKeyId", key.getId());
|
||||
}
|
||||
|
||||
private static Boolean resolveBoolean(JsonNode props, String name, ProvisionContext ctx) {
|
||||
String resolved = ctx.resolveOptional(props, name);
|
||||
return resolved == null || resolved.isBlank() ? null : Boolean.parseBoolean(resolved);
|
||||
}
|
||||
|
||||
private static void rejectIfChanged(String property, String existing, String requested) {
|
||||
if (!Objects.equals(blankToNull(existing), blankToNull(requested))) {
|
||||
throw replacementNotSupported(property);
|
||||
|
||||
+184
-6
@@ -14,18 +14,21 @@ import io.floci.aws.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUser;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.floci.aws.services.elasticache.model.Endpoint;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroup;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupSettings;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provisions AWS::ElastiCache::CacheCluster, SubnetGroup, User and UserGroup. A cache cluster needs
|
||||
* Provisions AWS::ElastiCache::CacheCluster, ReplicationGroup, SubnetGroup, User and UserGroup. A cache cluster needs
|
||||
* the Memcached service as well as the Redis one, because the two engines keep their clusters in
|
||||
* separate stores.
|
||||
*/
|
||||
@@ -36,6 +39,7 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private static final String CACHE_CLUSTER = "AWS::ElastiCache::CacheCluster";
|
||||
private static final String REPLICATION_GROUP = "AWS::ElastiCache::ReplicationGroup";
|
||||
private static final String SUBNET_GROUP = "AWS::ElastiCache::SubnetGroup";
|
||||
private static final String USER = "AWS::ElastiCache::User";
|
||||
private static final String USER_GROUP = "AWS::ElastiCache::UserGroup";
|
||||
@@ -45,7 +49,16 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
private static final List<String> UNSUPPORTED_CLUSTER_PROPERTIES = List.of("CacheSecurityGroupNames",
|
||||
"NotificationTopicArn", "AZMode", "PreferredAvailabilityZones", "LogDeliveryConfigurations",
|
||||
"SnapshotArns", "SnapshotName");
|
||||
private static final List<String> UNSUPPORTED_REPLICATION_GROUP_PROPERTIES = List.of("CacheSecurityGroupNames",
|
||||
"NotificationTopicArn", "PreferredCacheClusterAZs", "LogDeliveryConfigurations", "SnapshotArns",
|
||||
"SnapshotName", "GlobalReplicationGroupId", "NodeGroupConfiguration", "PrimaryClusterId",
|
||||
"SnapshottingClusterId", "DataTieringEnabled");
|
||||
private static final List<String> REPLICATION_GROUP_ENDPOINT_ATTRIBUTES = List.of(
|
||||
"PrimaryEndPoint.Address", "PrimaryEndPoint.Port", "ReaderEndPoint.Address", "ReaderEndPoint.Port",
|
||||
"ReadEndPoint.Addresses", "ReadEndPoint.Addresses.List", "ReadEndPoint.Ports", "ReadEndPoint.Ports.List",
|
||||
"ConfigurationEndPoint.Address", "ConfigurationEndPoint.Port");
|
||||
private static final int CLUSTER_ID_MAX_LENGTH = 50;
|
||||
private static final int REPLICATION_GROUP_ID_MAX_LENGTH = 40;
|
||||
private static final int SUBNET_GROUP_NAME_MAX_LENGTH = 255;
|
||||
|
||||
private final ElastiCacheService elastiCacheService;
|
||||
@@ -60,7 +73,12 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
@Override
|
||||
public Set<String> resourceTypes() {
|
||||
return Set.of(CACHE_CLUSTER, SUBNET_GROUP, USER, USER_GROUP);
|
||||
return Set.of(CACHE_CLUSTER, REPLICATION_GROUP, SUBNET_GROUP, USER, USER_GROUP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<String>> jsonAttributes() {
|
||||
return Map.of(REPLICATION_GROUP, Set.of("ReadEndPoint.Addresses.List", "ReadEndPoint.Ports.List"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,6 +89,7 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
Map<String, String> attributesBefore = Map.copyOf(r.getAttributes());
|
||||
switch (r.getResourceType()) {
|
||||
case CACHE_CLUSTER -> provisionCacheCluster(r, props, ctx);
|
||||
case REPLICATION_GROUP -> provisionReplicationGroup(r, props, ctx);
|
||||
case SUBNET_GROUP -> provisionSubnetGroup(r, props, ctx);
|
||||
case USER -> provisionUser(r, props, ctx);
|
||||
case USER_GROUP -> provisionUserGroup(r, props, ctx);
|
||||
@@ -209,10 +228,10 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
putEndpointAttributes(r, cluster);
|
||||
}
|
||||
|
||||
private void warnUnsupportedClusterProperties(String id, JsonNode props) {
|
||||
for (String name : UNSUPPORTED_CLUSTER_PROPERTIES) {
|
||||
private static void warnUnsupportedProperties(String kind, String id, JsonNode props, List<String> names) {
|
||||
for (String name : names) {
|
||||
if (props.hasNonNull(name)) {
|
||||
LOG.warnv("ElastiCache cache cluster {0}: {1} is accepted and ignored", id, name);
|
||||
LOG.warnv("ElastiCache {0} {1}: {2} is accepted and ignored", kind, id, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,7 +250,7 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
|
||||
private CacheCluster createCluster(String id, String engine, Integer port, JsonNode props,
|
||||
ProvisionContext ctx) {
|
||||
warnUnsupportedClusterProperties(id, props);
|
||||
warnUnsupportedProperties("cache cluster", id, props, UNSUPPORTED_CLUSTER_PROPERTIES);
|
||||
List<String> securityGroupIds = ctx.resolveStringList(props, "VpcSecurityGroupIds");
|
||||
ElastiCacheService.CreateCacheClusterRequest request = new ElastiCacheService.CreateCacheClusterRequest(
|
||||
id,
|
||||
@@ -294,6 +313,163 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionReplicationGroup(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String description = ctx.resolveOptional(props, "ReplicationGroupDescription");
|
||||
if (description == null || description.isBlank()) {
|
||||
throw new AwsException("ValidationException", "ReplicationGroupDescription is required", 400);
|
||||
}
|
||||
String explicitId = ctx.resolveOptional(props, "ReplicationGroupId");
|
||||
if (explicitId != null && explicitId.length() > REPLICATION_GROUP_ID_MAX_LENGTH) {
|
||||
throw new AwsException("ValidationException",
|
||||
"ReplicationGroupId exceeds maximum length of " + REPLICATION_GROUP_ID_MAX_LENGTH, 400);
|
||||
}
|
||||
|
||||
ReplicationGroup prior = ctx.isUpdate() ? findReplicationGroup(ctx.priorPhysicalId()) : null;
|
||||
// As for a cache cluster: a create-only change replaces the group, which needs a new id.
|
||||
boolean createOnlyChanged = prior != null && ctx.changes(REPLICATION_GROUP, props).requiresReplacement();
|
||||
if (createOnlyChanged && explicitId != null && explicitId.equals(ctx.priorPhysicalId())) {
|
||||
throw new AwsException("InvalidParameterValue", "Updating a create-only property of replication group "
|
||||
+ explicitId + " requires a new ReplicationGroupId", 400);
|
||||
}
|
||||
String id = createOnlyChanged && explicitId == null
|
||||
? ctx.generatePhysicalName(r.getLogicalId(), REPLICATION_GROUP_ID_MAX_LENGTH, true)
|
||||
: ctx.stablePhysicalName(explicitId, r.getLogicalId(), REPLICATION_GROUP_ID_MAX_LENGTH, true);
|
||||
|
||||
ReplicationGroup group;
|
||||
if (ctx.reusesPriorEntity(id)) {
|
||||
group = prior != null ? prior : findReplicationGroup(id);
|
||||
if (group == null) {
|
||||
LOG.warnv("ElastiCache replication group {0} was deleted outside the stack, recreating it", id);
|
||||
group = createReplicationGroup(id, description, props, ctx);
|
||||
} else {
|
||||
warnIgnoredReplicationGroupChanges(id, group, description, props, ctx);
|
||||
}
|
||||
} else {
|
||||
group = createReplicationGroup(id, description, props, ctx);
|
||||
}
|
||||
|
||||
r.setPhysicalId(id);
|
||||
putReplicationGroupEndpointAttributes(r, group);
|
||||
}
|
||||
|
||||
private static void warnIgnoredReplicationGroupChanges(String id, ReplicationGroup group, String description,
|
||||
JsonNode props, ProvisionContext ctx) {
|
||||
List<String> changed = new ArrayList<>();
|
||||
if (!description.equals(group.getDescription())) {
|
||||
changed.add("ReplicationGroupDescription");
|
||||
}
|
||||
String nodeType = ctx.resolveOptional(props, "CacheNodeType");
|
||||
if (nodeType != null && !nodeType.equals(group.getCacheNodeType())) {
|
||||
changed.add("CacheNodeType");
|
||||
}
|
||||
String version = ctx.resolveOptional(props, "EngineVersion");
|
||||
if (version != null && !version.equals(group.getEngineVersion())) {
|
||||
changed.add("EngineVersion");
|
||||
}
|
||||
Integer clusters = ctx.resolveOptionalInt(props, "NumCacheClusters");
|
||||
if (clusters != null && clusters != group.getNumCacheClusters()) {
|
||||
changed.add("NumCacheClusters");
|
||||
}
|
||||
// the service stores user group ids in lowercase
|
||||
Set<String> userGroupIds = new HashSet<>();
|
||||
ctx.resolveStringList(props, "UserGroupIds").forEach(g -> userGroupIds.add(g.toLowerCase(Locale.ROOT)));
|
||||
if (!userGroupIds.equals(group.getUserGroupIds())) {
|
||||
changed.add("UserGroupIds");
|
||||
}
|
||||
if (!changed.isEmpty()) {
|
||||
LOG.warnv("ElastiCache replication group {0}: in-place modification is not supported, changes to {1} "
|
||||
+ "are ignored", id, String.join(", ", changed));
|
||||
}
|
||||
}
|
||||
|
||||
private ReplicationGroup createReplicationGroup(String id, String description, JsonNode props,
|
||||
ProvisionContext ctx) {
|
||||
warnUnsupportedProperties("replication group", id, props, UNSUPPORTED_REPLICATION_GROUP_PROPERTIES);
|
||||
String authToken = ctx.resolveOptional(props, "AuthToken");
|
||||
boolean hasAuthToken = authToken != null && !authToken.isBlank();
|
||||
List<String> userGroupIds = ctx.resolveStringList(props, "UserGroupIds");
|
||||
List<String> securityGroupIds = ctx.resolveStringList(props, "SecurityGroupIds");
|
||||
ReplicationGroupSettings settings = new ReplicationGroupSettings(
|
||||
ctx.resolveOptionalBoolean(props, "AtRestEncryptionEnabled"),
|
||||
ctx.resolveOptional(props, "KmsKeyId"),
|
||||
ctx.resolveOptionalInt(props, "SnapshotRetentionLimit"),
|
||||
ctx.resolveOptional(props, "SnapshotWindow"),
|
||||
ctx.resolveOptional(props, "TransitEncryptionMode"),
|
||||
ctx.resolveOptionalBoolean(props, "TransitEncryptionEnabled"));
|
||||
return elastiCacheService.createReplicationGroup(new ElastiCacheService.CreateReplicationGroupRequest(
|
||||
id,
|
||||
description,
|
||||
hasAuthToken ? AuthMode.PASSWORD : AuthMode.NO_AUTH,
|
||||
hasAuthToken ? authToken : null,
|
||||
ctx.region(),
|
||||
ctx.resolveOptional(props, "Engine"),
|
||||
ctx.resolveOptional(props, "EngineVersion"),
|
||||
ctx.resolveOptional(props, "CacheNodeType"),
|
||||
ctx.resolveOptional(props, "CacheParameterGroupName"),
|
||||
ctx.resolveOptional(props, "CacheSubnetGroupName"),
|
||||
ctx.resolveOptional(props, "ClusterMode"),
|
||||
ctx.resolveOptionalInt(props, "NumNodeGroups"),
|
||||
ctx.resolveOptionalInt(props, "ReplicasPerNodeGroup"),
|
||||
ctx.resolveOptionalInt(props, "NumCacheClusters"),
|
||||
ctx.resolveOptionalBoolean(props, "AutomaticFailoverEnabled"),
|
||||
ctx.resolveOptionalBoolean(props, "MultiAZEnabled"),
|
||||
ctx.resolveOptionalInt(props, "Port"),
|
||||
settings,
|
||||
ctx.resolveTags(props, "Tags"),
|
||||
userGroupIds.isEmpty() ? null : userGroupIds,
|
||||
securityGroupIds.isEmpty() ? null : securityGroupIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the endpoint attributes AWS exposes for the group's mode: a cluster-mode group answers on its
|
||||
* ConfigurationEndPoint, any other on its primary and reader endpoints and one read endpoint per node.
|
||||
*/
|
||||
private void putReplicationGroupEndpointAttributes(StackResource r, ReplicationGroup group) {
|
||||
REPLICATION_GROUP_ENDPOINT_ATTRIBUTES.forEach(r.getAttributes()::remove);
|
||||
Endpoint endpoint = group.getConfigurationEndpoint();
|
||||
if (endpoint == null) {
|
||||
return;
|
||||
}
|
||||
String port = String.valueOf(endpoint.port());
|
||||
if (group.isClusterEnabled()) {
|
||||
r.getAttributes().put("ConfigurationEndPoint.Address", endpoint.address());
|
||||
r.getAttributes().put("ConfigurationEndPoint.Port", port);
|
||||
return;
|
||||
}
|
||||
r.getAttributes().put("PrimaryEndPoint.Address", endpoint.address());
|
||||
r.getAttributes().put("PrimaryEndPoint.Port", port);
|
||||
r.getAttributes().put("ReaderEndPoint.Address", endpoint.address());
|
||||
r.getAttributes().put("ReaderEndPoint.Port", port);
|
||||
List<String> addresses = new ArrayList<>();
|
||||
List<String> ports = new ArrayList<>();
|
||||
for (ElastiCacheService.MemberCacheCluster member : elastiCacheService.memberCacheClusters(group)) {
|
||||
addresses.add(endpoint.address());
|
||||
ports.add(String.valueOf(member.port()));
|
||||
}
|
||||
r.getAttributes().put("ReadEndPoint.Addresses", String.join(",", addresses));
|
||||
r.getAttributes().put("ReadEndPoint.Ports", String.join(",", ports));
|
||||
try {
|
||||
r.getAttributes().put("ReadEndPoint.Addresses.List", MAPPER.writeValueAsString(addresses));
|
||||
r.getAttributes().put("ReadEndPoint.Ports.List", MAPPER.writeValueAsString(ports));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private ReplicationGroup findReplicationGroup(String groupId) {
|
||||
if (groupId == null || groupId.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return elastiCacheService.getReplicationGroup(groupId);
|
||||
} catch (AwsException e) {
|
||||
if ("ReplicationGroupNotFoundFault".equals(e.getErrorCode())) {
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private void provisionSubnetGroup(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String description = ctx.resolveOptional(props, "Description");
|
||||
if (description == null || description.isBlank()) {
|
||||
@@ -448,6 +624,8 @@ public class ElastiCacheCfnProvisioner implements CfnResourceProvisioner {
|
||||
elastiCacheService.deleteCacheCluster(physicalId);
|
||||
}
|
||||
}, "CacheClusterNotFound");
|
||||
case REPLICATION_GROUP -> CfnDeletes.safeDelete("ElastiCache replication group", physicalId,
|
||||
() -> elastiCacheService.deleteReplicationGroup(physicalId), "ReplicationGroupNotFoundFault");
|
||||
case SUBNET_GROUP -> CfnDeletes.safeDelete("ElastiCache subnet group", physicalId,
|
||||
() -> elastiCacheService.deleteCacheSubnetGroup(physicalId), "CacheSubnetGroupNotFoundFault");
|
||||
case USER_GROUP -> CfnDeletes.safeDelete("ElastiCache user group", physicalId,
|
||||
|
||||
+5
-14
@@ -82,13 +82,13 @@ public class IotAuthorizerCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
String explicitName = resolvePresent(props, "AuthorizerName", ctx);
|
||||
boolean hasExplicitName = explicitName != null;
|
||||
String signingDisabled = resolveBoolean(props, "SigningDisabled", ctx);
|
||||
Boolean signingDisabled = ctx.resolveOptionalBoolean(props, "SigningDisabled");
|
||||
ObjectNode declared = MAPPER.createObjectNode().put("authorizerFunctionArn", functionArn);
|
||||
putIfPresent(declared, "status", resolvePresent(props, "Status", ctx));
|
||||
putIfPresent(declared, "tokenKeyName", resolvePresent(props, "TokenKeyName", ctx));
|
||||
String caching = resolveBoolean(props, "EnableCachingForHttp", ctx);
|
||||
Boolean caching = ctx.resolveOptionalBoolean(props, "EnableCachingForHttp");
|
||||
if (caching != null) {
|
||||
declared.put("enableCachingForHttp", Boolean.parseBoolean(caching));
|
||||
declared.put("enableCachingForHttp", caching);
|
||||
}
|
||||
JsonNode keys = props == null ? null : ctx.engine().resolveNode(props.get("TokenSigningPublicKeys"));
|
||||
if (keys != null && keys.isObject()) {
|
||||
@@ -111,7 +111,7 @@ public class IotAuthorizerCfnProvisioner implements CfnResourceProvisioner {
|
||||
? authorizerService.describeAuthorizer(ctx.priorPhysicalId(), ctx.region())
|
||||
: null;
|
||||
// ponytail: compared with the stored flag, so an absent SigningDisabled reads as its API default false.
|
||||
boolean signingChanged = prior != null && prior.isSigningDisabled() != Boolean.parseBoolean(signingDisabled);
|
||||
boolean signingChanged = prior != null && prior.isSigningDisabled() != Boolean.TRUE.equals(signingDisabled);
|
||||
boolean nameWasGenerated = NAME_MODE_GENERATED.equals(attributesBefore.get(NAME_MODE_ATTR));
|
||||
if ((signingChanged || nameWasGenerated) && hasExplicitName && explicitName.equals(ctx.priorPhysicalId())) {
|
||||
throw new AwsException("ValidationError",
|
||||
@@ -132,7 +132,7 @@ public class IotAuthorizerCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
} else {
|
||||
if (signingDisabled != null) {
|
||||
declared.put("signingDisabled", Boolean.parseBoolean(signingDisabled));
|
||||
declared.put("signingDisabled", signingDisabled);
|
||||
}
|
||||
if (!tags.isEmpty()) {
|
||||
ArrayNode tagList = declared.putArray("tags");
|
||||
@@ -181,15 +181,6 @@ public class IotAuthorizerCfnProvisioner implements CfnResourceProvisioner {
|
||||
return literal || (value != null && !value.isEmpty()) ? value : null;
|
||||
}
|
||||
|
||||
/** A present boolean property, refused unless it is true or false rather than read as false. */
|
||||
private static String resolveBoolean(JsonNode props, String name, ProvisionContext ctx) {
|
||||
String value = resolvePresent(props, name, ctx);
|
||||
if (value != null && !"true".equalsIgnoreCase(value) && !"false".equalsIgnoreCase(value)) {
|
||||
throw new AwsException("ValidationError", TYPE + " " + name + " must be true or false, got " + value, 400);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void putIfPresent(ObjectNode body, String field, String value) {
|
||||
if (value != null) {
|
||||
body.put(field, value);
|
||||
|
||||
@@ -204,6 +204,24 @@ public record ProvisionContext(CloudFormationTemplateEngine engine, String regio
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an optional boolean property, or null when it is absent or explicitly null. An intrinsic
|
||||
* that resolves to empty ({@code AWS::NoValue}) stays null too. Any other value has to be true or
|
||||
* false in any case, the string forms CloudFormation also accepts included; anything else, a
|
||||
* whitespace-only intrinsic result included, is refused rather than read as false.
|
||||
*/
|
||||
public Boolean resolveOptionalBoolean(JsonNode props, String name) {
|
||||
String value = resolveOptional(props, name);
|
||||
if (value == null || (value.isEmpty() && !props.get(name).isTextual())) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = value.trim();
|
||||
if (!"true".equalsIgnoreCase(trimmed) && !"false".equalsIgnoreCase(trimmed)) {
|
||||
throw new AwsException("ValidationError", "Value of property " + name + " must be a boolean.", 400);
|
||||
}
|
||||
return Boolean.parseBoolean(trimmed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves an optional property through the engine, falling back to {@code defaultValue} when it
|
||||
* is absent or resolves to blank. Shared by the per-service provisioners so none carries its own
|
||||
|
||||
+1
-2
@@ -347,8 +347,7 @@ public class StackSetCfnProvisioner implements CfnResourceProvisioner {
|
||||
}
|
||||
|
||||
private static Boolean optionalBoolean(JsonNode node, String name, ProvisionContext ctx) {
|
||||
String value = ctx.resolveOptional(node.isObject() ? node : null, name);
|
||||
return value == null || value.isBlank() ? null : Boolean.valueOf(value);
|
||||
return ctx.resolveOptionalBoolean(node.isObject() ? node : null, name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -526,6 +526,19 @@
|
||||
"Engine",
|
||||
"NetworkType"
|
||||
],
|
||||
"AWS::ElastiCache::ReplicationGroup": [
|
||||
"AtRestEncryptionEnabled",
|
||||
"CacheSubnetGroupName",
|
||||
"DataTieringEnabled",
|
||||
"GlobalReplicationGroupId",
|
||||
"KmsKeyId",
|
||||
"NetworkType",
|
||||
"Port",
|
||||
"PreferredCacheClusterAZs",
|
||||
"ReplicationGroupId",
|
||||
"SnapshotArns",
|
||||
"SnapshotName"
|
||||
],
|
||||
"AWS::ElastiCache::ServerlessCache": [
|
||||
"ServerlessCacheName",
|
||||
"KmsKeyId",
|
||||
|
||||
@@ -17,9 +17,13 @@ import software.amazon.awssdk.services.elasticache.ElastiCacheClient;
|
||||
import software.amazon.awssdk.services.elasticache.model.CacheCluster;
|
||||
import software.amazon.awssdk.services.elasticache.model.CacheSubnetGroupNotFoundException;
|
||||
import software.amazon.awssdk.services.elasticache.model.ElastiCacheException;
|
||||
import software.amazon.awssdk.services.elasticache.model.Endpoint;
|
||||
import software.amazon.awssdk.services.elasticache.model.ReplicationGroup;
|
||||
import software.amazon.awssdk.services.elasticache.model.ReplicationGroupNotFoundException;
|
||||
import software.amazon.awssdk.services.elasticache.model.UserGroupNotFoundException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
@@ -215,6 +219,25 @@ class ElastiCacheCfnIntegrationTest {
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void userGroupCanListTheBuiltInDefaultUser() {
|
||||
String stack = "elasticache-cfn-builtin-member-it";
|
||||
cloudFormation(stack, "CreateStack", """
|
||||
{"Resources": {"UserGroup": {"Type": "AWS::ElastiCache::UserGroup",
|
||||
"Properties": {"UserGroupId": "cfn-it-builtin-members", "Engine": "redis",
|
||||
"UserIds": ["default"]}}}}
|
||||
""");
|
||||
describeStacks(stack, "CREATE_COMPLETE");
|
||||
|
||||
try (ElastiCacheClient client = client()) {
|
||||
assertEquals(List.of("default"), client.describeUserGroups(r -> r.userGroupId("cfn-it-builtin-members"))
|
||||
.userGroups().getFirst().userIds());
|
||||
}
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheClusterExposesEndpoints() throws Exception {
|
||||
Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the cache data plane");
|
||||
@@ -237,6 +260,68 @@ class ElastiCacheCfnIntegrationTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void replicationGroupWithBuiltInDefaultUserExposesEndpoints() throws Exception {
|
||||
Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the cache data plane");
|
||||
String stack = "elasticache-cfn-replication-group-it";
|
||||
// the property shapes a Serverless Framework template sends: a numeric EngineVersion, string scalars
|
||||
cloudFormation(stack, "CreateStack", """
|
||||
{
|
||||
"Resources": {
|
||||
"Vpc": {"Type": "AWS::EC2::VPC", "Properties": {"CidrBlock": "10.74.0.0/16"}},
|
||||
"Subnet": {"Type": "AWS::EC2::Subnet",
|
||||
"Properties": {"VpcId": {"Ref": "Vpc"}, "CidrBlock": "10.74.0.0/24"}},
|
||||
"SecurityGroup": {"Type": "AWS::EC2::SecurityGroup",
|
||||
"Properties": {"GroupDescription": "cache", "VpcId": {"Ref": "Vpc"}}},
|
||||
"SubnetGroup": {"Type": "AWS::ElastiCache::SubnetGroup",
|
||||
"Properties": {"Description": "example", "SubnetIds": [{"Ref": "Subnet"}]}},
|
||||
"AppUser": {"Type": "AWS::ElastiCache::User",
|
||||
"Properties": {"UserId": "cfn-it-rg-app", "UserName": "cfn-it-rg-app", "Engine": "redis",
|
||||
"AccessString": "on ~* +@all",
|
||||
"AuthenticationMode": {"Type": "password",
|
||||
"Passwords": ["example-password-0123456789"]}}},
|
||||
"UserGroup": {"Type": "AWS::ElastiCache::UserGroup",
|
||||
"Properties": {"UserGroupId": "cfn-it-rg-users", "Engine": "redis",
|
||||
"UserIds": ["default", {"Ref": "AppUser"}]}},
|
||||
"Redis": {"Type": "AWS::ElastiCache::ReplicationGroup",
|
||||
"Properties": {"ReplicationGroupId": "cfn-it-rg", "ReplicationGroupDescription": "cache",
|
||||
"Engine": "redis", "EngineVersion": 7.1, "Port": 6379,
|
||||
"CacheNodeType": "cache.t3.micro", "NumCacheClusters": "1",
|
||||
"AutomaticFailoverEnabled": "false",
|
||||
"SecurityGroupIds": [{"Ref": "SecurityGroup"}],
|
||||
"CacheSubnetGroupName": {"Ref": "SubnetGroup"},
|
||||
"UserGroupIds": [{"Ref": "UserGroup"}],
|
||||
"TransitEncryptionEnabled": true}}
|
||||
},
|
||||
"Outputs": {
|
||||
"Ref": {"Value": {"Ref": "Redis"}},
|
||||
"Address": {"Value": {"Fn::GetAtt": ["Redis", "PrimaryEndPoint.Address"]}},
|
||||
"Port": {"Value": {"Fn::GetAtt": ["Redis", "PrimaryEndPoint.Port"]}},
|
||||
"ReadPorts": {"Value": {"Fn::Join": [",", {"Fn::GetAtt": ["Redis", "ReadEndPoint.Ports.List"]}]}}
|
||||
}
|
||||
}
|
||||
""");
|
||||
String stacks = describeStacks(stack, "CREATE_COMPLETE");
|
||||
|
||||
assertEquals("cfn-it-rg", outputValue(stacks, "Ref"));
|
||||
try (ElastiCacheClient client = client()) {
|
||||
ReplicationGroup group = client.describeReplicationGroups(r -> r.replicationGroupId("cfn-it-rg"))
|
||||
.replicationGroups().getFirst();
|
||||
Endpoint primary = group.nodeGroups().getFirst().primaryEndpoint();
|
||||
assertEquals(primary.address(), outputValue(stacks, "Address"));
|
||||
assertEquals(String.valueOf(primary.port()), outputValue(stacks, "Port"));
|
||||
assertEquals(String.valueOf(primary.port()), outputValue(stacks, "ReadPorts"));
|
||||
assertEquals(List.of("cfn-it-rg-users"), group.userGroupIds());
|
||||
assertTrue(group.transitEncryptionEnabled());
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
|
||||
assertThrows(ReplicationGroupNotFoundException.class,
|
||||
() -> client.describeReplicationGroups(r -> r.replicationGroupId("cfn-it-rg")));
|
||||
}
|
||||
}
|
||||
|
||||
private static void cloudFormation(String stack, String action, String templateBody) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
+146
@@ -15,9 +15,13 @@ import io.floci.aws.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUser;
|
||||
import io.floci.aws.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.floci.aws.services.elasticache.model.Endpoint;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroup;
|
||||
import io.floci.aws.services.elasticache.model.ReplicationGroupStatus;
|
||||
import io.floci.aws.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -105,6 +109,148 @@ class ElastiCacheCfnProvisionerTest {
|
||||
verify(memcached, never()).createCacheCluster(any());
|
||||
}
|
||||
|
||||
private ReplicationGroup replicationGroup(String id, int numCacheClusters) {
|
||||
ReplicationGroup group = new ReplicationGroup(id, "d", ReplicationGroupStatus.AVAILABLE, AuthMode.NO_AUTH,
|
||||
new Endpoint("localhost", 6420), Instant.now(), 6420);
|
||||
group.setNumCacheClusters(numCacheClusters);
|
||||
return group;
|
||||
}
|
||||
|
||||
@Test
|
||||
void replicationGroupTakesLooseScalarsAndExposesItsEndpoints() throws Exception {
|
||||
ReplicationGroup created = replicationGroup("app-redis", 2);
|
||||
when(cache.createReplicationGroup(any(ElastiCacheService.CreateReplicationGroupRequest.class)))
|
||||
.thenReturn(created);
|
||||
when(cache.memberCacheClusters(created)).thenReturn(List.of(
|
||||
new ElastiCacheService.MemberCacheCluster(created, "app-redis-001", 6420, true),
|
||||
new ElastiCacheService.MemberCacheCluster(created, "app-redis-002", 6420, false)));
|
||||
StackResource r = resource("AWS::ElastiCache::ReplicationGroup", "Redis");
|
||||
|
||||
// EngineVersion as a number, NumCacheClusters and AutomaticFailoverEnabled as strings
|
||||
provisioner.provision(r, props("""
|
||||
{"ReplicationGroupId":"app-redis","ReplicationGroupDescription":"d","Engine":"redis",
|
||||
"EngineVersion":7.1,"Port":6379,"CacheNodeType":"cache.t3.micro","NumCacheClusters":"2",
|
||||
"AutomaticFailoverEnabled":"false","SecurityGroupIds":["sg-1"],"CacheSubnetGroupName":"sng",
|
||||
"UserGroupIds":["users"],"TransitEncryptionEnabled":true}
|
||||
"""), ctx(null));
|
||||
|
||||
ArgumentCaptor<ElastiCacheService.CreateReplicationGroupRequest> request =
|
||||
ArgumentCaptor.forClass(ElastiCacheService.CreateReplicationGroupRequest.class);
|
||||
verify(cache).createReplicationGroup(request.capture());
|
||||
ElastiCacheService.CreateReplicationGroupRequest sent = request.getValue();
|
||||
assertEquals("app-redis", sent.replicationGroupId());
|
||||
assertEquals("7.1", sent.engineVersion());
|
||||
assertEquals(2, sent.numCacheClusters());
|
||||
assertEquals(false, sent.automaticFailoverEnabled());
|
||||
assertEquals(6379, sent.port());
|
||||
assertEquals(true, sent.settings().transitEncryptionEnabled());
|
||||
assertEquals(List.of("users"), sent.userGroupIds());
|
||||
assertEquals(List.of("sg-1"), sent.securityGroupIds());
|
||||
assertEquals("sng", sent.cacheSubnetGroupName());
|
||||
assertEquals(AuthMode.NO_AUTH, sent.authMode());
|
||||
|
||||
assertEquals("app-redis", r.getPhysicalId());
|
||||
assertEquals("localhost", r.getAttributes().get("PrimaryEndPoint.Address"));
|
||||
assertEquals("6420", r.getAttributes().get("PrimaryEndPoint.Port"));
|
||||
assertEquals("localhost", r.getAttributes().get("ReaderEndPoint.Address"));
|
||||
assertEquals("6420", r.getAttributes().get("ReaderEndPoint.Port"));
|
||||
assertEquals("localhost,localhost", r.getAttributes().get("ReadEndPoint.Addresses"));
|
||||
assertEquals("6420,6420", r.getAttributes().get("ReadEndPoint.Ports"));
|
||||
assertEquals(mapper.readTree("[\"6420\",\"6420\"]"), provisioner.attributeValue(
|
||||
"AWS::ElastiCache::ReplicationGroup", "ReadEndPoint.Ports.List",
|
||||
r.getAttributes().get("ReadEndPoint.Ports.List")));
|
||||
assertNull(r.getAttributes().get("ConfigurationEndPoint.Address"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterModeReplicationGroupExposesOnlyTheConfigurationEndpoint() throws Exception {
|
||||
ReplicationGroup created = replicationGroup("sharded", 1);
|
||||
created.setClusterEnabled(true);
|
||||
when(cache.createReplicationGroup(any(ElastiCacheService.CreateReplicationGroupRequest.class)))
|
||||
.thenReturn(created);
|
||||
StackResource r = resource("AWS::ElastiCache::ReplicationGroup", "Redis");
|
||||
|
||||
provisioner.provision(r, props("""
|
||||
{"ReplicationGroupId":"sharded","ReplicationGroupDescription":"d","ClusterMode":"enabled",
|
||||
"NumNodeGroups":2}
|
||||
"""), ctx(null));
|
||||
|
||||
assertEquals("6420", r.getAttributes().get("ConfigurationEndPoint.Port"));
|
||||
assertNull(r.getAttributes().get("PrimaryEndPoint.Address"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedReplicationGroupBooleanIsRejected() throws Exception {
|
||||
StackResource r = resource("AWS::ElastiCache::ReplicationGroup", "Redis");
|
||||
assertThrows(AwsException.class, () -> provisioner.provision(r, props("""
|
||||
{"ReplicationGroupDescription":"d","AutomaticFailoverEnabled":"yes"}
|
||||
"""), ctx(null)));
|
||||
verify(cache, never()).createReplicationGroup(any(ElastiCacheService.CreateReplicationGroupRequest.class));
|
||||
}
|
||||
|
||||
private List<String> ignoredChangeWarnings(StackResource r, String props, String priorProps) {
|
||||
return LogCapture.capture(ElastiCacheCfnProvisioner.class, () -> {
|
||||
try {
|
||||
provisioner.provision(r, props(props), ctx("app-redis", priorProps));
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}).stream()
|
||||
.map(record -> MessageFormat.format(record.getMessage(), record.getParameters()))
|
||||
.filter(message -> message.contains("in-place modification is not supported"))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Test
|
||||
void replicationGroupUpdateWithSameIdNamesTheChangesItIgnores() throws Exception {
|
||||
ReplicationGroup existing = replicationGroup("app-redis", 1);
|
||||
existing.setCacheNodeType("cache.t3.micro");
|
||||
when(cache.getReplicationGroup("app-redis")).thenReturn(existing);
|
||||
StackResource r = resource("AWS::ElastiCache::ReplicationGroup", "Redis");
|
||||
|
||||
List<String> warnings = ignoredChangeWarnings(r, """
|
||||
{"ReplicationGroupId":"app-redis","ReplicationGroupDescription":"changed","CacheNodeType":"cache.t3.small",
|
||||
"NumCacheClusters":"1"}
|
||||
""", """
|
||||
{"ReplicationGroupId":"app-redis","ReplicationGroupDescription":"d","CacheNodeType":"cache.t3.micro",
|
||||
"NumCacheClusters":"1"}
|
||||
""");
|
||||
|
||||
verify(cache, never()).createReplicationGroup(any(ElastiCacheService.CreateReplicationGroupRequest.class));
|
||||
assertEquals("app-redis", r.getPhysicalId());
|
||||
assertEquals("6420", r.getAttributes().get("PrimaryEndPoint.Port"));
|
||||
assertEquals(List.of("ElastiCache replication group app-redis: in-place modification is not supported, "
|
||||
+ "changes to ReplicationGroupDescription, CacheNodeType are ignored"), warnings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void replicationGroupUpdateWithoutChangesWarnsNothing() throws Exception {
|
||||
ReplicationGroup existing = replicationGroup("app-redis", 1);
|
||||
existing.setCacheNodeType("cache.t3.micro");
|
||||
existing.setEngineVersion("7.1");
|
||||
existing.getUserGroupIds().add("users");
|
||||
when(cache.getReplicationGroup("app-redis")).thenReturn(existing);
|
||||
String template = """
|
||||
{"ReplicationGroupId":"app-redis","ReplicationGroupDescription":"d","CacheNodeType":"cache.t3.micro",
|
||||
"EngineVersion":7.1,"NumCacheClusters":"1","UserGroupIds":["Users"],"Tags":[{"Key":"a","Value":"b"}]}
|
||||
""";
|
||||
|
||||
List<String> warnings = ignoredChangeWarnings(resource("AWS::ElastiCache::ReplicationGroup", "Redis"),
|
||||
template, template);
|
||||
|
||||
assertEquals(List.of(), warnings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void replicationGroupDeleteToleratesAGroupAlreadyGone() {
|
||||
doThrow(new AwsException("ReplicationGroupNotFoundFault", "gone", 404))
|
||||
.when(cache).deleteReplicationGroup("app-redis");
|
||||
|
||||
provisioner.delete("AWS::ElastiCache::ReplicationGroup", "app-redis", "us-east-1");
|
||||
|
||||
verify(cache).deleteReplicationGroup("app-redis");
|
||||
}
|
||||
|
||||
@Test
|
||||
void memcachedCacheClusterGoesToMemcachedServiceWithConfigurationEndpoint() throws Exception {
|
||||
CacheCluster created = new CacheCluster("mc", CacheClusterStatus.AVAILABLE, "memcached", "1.6",
|
||||
|
||||
+1
-1
@@ -271,7 +271,7 @@ class IotAuthorizerCfnProvisionerTest {
|
||||
AwsException error = assertThrows(AwsException.class, () -> update(resource, properties));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals("AWS::IoT::Authorizer EnableCachingForHttp must be true or false, got ", error.getMessage());
|
||||
assertEquals("Value of property EnableCachingForHttp must be a boolean.", error.getMessage());
|
||||
verify(service, never()).updateAuthorizer(anyString(), any(), anyString());
|
||||
assertTrue(authorizers.get("auth").isEnableCachingForHttp());
|
||||
}
|
||||
|
||||
+30
@@ -291,6 +291,36 @@ class ProvisionContextTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveOptionalBooleanReadsABooleanAndRefusesAnythingElse() {
|
||||
ProvisionContext ctx = context(null);
|
||||
JsonNode flag = props("{\"Ref\": \"Flag\"}");
|
||||
when(engine.resolve(flag)).thenReturn("TRUE");
|
||||
|
||||
assertEquals(true, ctx.resolveOptionalBoolean(props("{\"On\": true}"), "On"), "a boolean");
|
||||
assertEquals(false, ctx.resolveOptionalBoolean(props("{\"On\": \"false\"}"), "On"), "a boolean string");
|
||||
assertEquals(false, ctx.resolveOptionalBoolean(props("{\"On\": \" False \"}"), "On"),
|
||||
"any case, surrounding blanks trimmed");
|
||||
assertEquals(true, ctx.resolveOptionalBoolean(props("{\"On\": {\"Ref\": \"Flag\"}}"), "On"),
|
||||
"an intrinsic's result");
|
||||
assertNull(ctx.resolveOptionalBoolean(props("{}"), "On"), "absent");
|
||||
assertNull(ctx.resolveOptionalBoolean(props("{\"On\": null}"), "On"), "explicitly null");
|
||||
assertNull(ctx.resolveOptionalBoolean(null, "On"), "no properties at all");
|
||||
assertNull(ctx.resolveOptionalBoolean(props("{\"On\": {\"Ref\": \"AWS::NoValue\"}}"), "On"),
|
||||
"an intrinsic that resolves to empty, as AWS::NoValue does");
|
||||
JsonNode whitespace = props("{\"Ref\": \"Blank\"}");
|
||||
when(engine.resolve(whitespace)).thenReturn(" ");
|
||||
AwsException blank = assertThrows(AwsException.class,
|
||||
() -> ctx.resolveOptionalBoolean(props("{\"On\": {\"Ref\": \"Blank\"}}"), "On"));
|
||||
assertEquals("Value of property On must be a boolean.", blank.getMessage(), "a whitespace intrinsic result");
|
||||
for (String literal : List.of("\"\"", "\"yes\"", "1", "0")) {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> ctx.resolveOptionalBoolean(props("{\"On\": " + literal + "}"), "On"), literal);
|
||||
assertEquals("ValidationError", e.getErrorCode(), literal);
|
||||
assertEquals("Value of property On must be a boolean.", e.getMessage(), literal);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void stablePhysicalNamePrefersTheTemplatesName() {
|
||||
assertEquals("chosen",
|
||||
|
||||
@@ -52,6 +52,11 @@ AWS::EKS::Cluster EncryptionConfigKeyArn not modeled: Floci does not apply envel
|
||||
AWS::EKS::Cluster Id not modeled: Floci identifies a cluster by its Name (the primary identifier and Ref), not a separate Id
|
||||
AWS::ElastiCache::CacheCluster ConfigurationEndpoint the whole object has no scalar GetAtt form; its members are set under the dotted ConfigurationEndpoint.* attributes, the form AWS GetAtt exposes (memcached only)
|
||||
AWS::ElastiCache::CacheCluster RedisEndpoint the whole object has no scalar GetAtt form; its members are set under the dotted RedisEndpoint.* attributes, the form AWS GetAtt exposes (redis and valkey only)
|
||||
AWS::ElastiCache::ReplicationGroup ConfigurationEndPoint the whole object has no scalar GetAtt form; its members are set under the dotted ConfigurationEndPoint.* attributes (cluster mode enabled only)
|
||||
AWS::ElastiCache::ReplicationGroup EffectiveDurability not emulated: Floci does not model replication group durability
|
||||
AWS::ElastiCache::ReplicationGroup PrimaryEndPoint the whole object has no scalar GetAtt form; its members are set under the dotted PrimaryEndPoint.* attributes (cluster mode disabled only)
|
||||
AWS::ElastiCache::ReplicationGroup ReadEndPoint the whole object has no scalar GetAtt form; its members are set under the dotted ReadEndPoint.Addresses(.List) and ReadEndPoint.Ports(.List) attributes (cluster mode disabled only)
|
||||
AWS::ElastiCache::ReplicationGroup ReaderEndPoint the whole object has no scalar GetAtt form; its members are set under the dotted ReaderEndPoint.* attributes (cluster mode disabled only)
|
||||
AWS::IAM::Policy Id not published: Floci uses the policy name for Ref, AWS returns an opaque generated identifier that Floci does not model
|
||||
AWS::IAM::ManagedPolicy AttachmentCount not published: the attachment count is dynamic and Floci does not expose it as a stable Fn::GetAtt value
|
||||
AWS::IAM::ManagedPolicy CreateDate not published: Floci does not surface the policy create date as an Fn::GetAtt value
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 5 and column 144.
|
@@ -107,6 +107,7 @@ AWS::EFS::MountTarget Id FileSystemId,IpAddress,IpAddressType,Ipv6Address,Securi
|
||||
AWS::EKS::Cluster Arn,CertificateAuthorityData,ClusterSecurityGroupId,EncryptionConfigKeyArn,Endpoint,Id,OpenIdConnectIssuerUrl AccessConfig,ActiveCertificateAuthorityId,BootstrapSelfManagedAddons,CertificateAuthority,ComputeConfig,ControlPlaneScalingConfig,DeletionProtection,EncryptionConfig,Force,KubeApiServerConfig,KubeControllerManagerConfig,KubeSchedulerConfig,KubernetesNetworkConfig,Logging,Name,OutpostConfig,RemoteNetworkConfig,ResourcesVpcConfig,RoleArn,RollbackConfig,StorageConfig,Tags,UpgradePolicy,Version,ZonalShiftConfig
|
||||
AWS::EKS::Nodegroup Arn,Id AmiType,CapacityType,ClusterName,DiskSize,ForceUpdateEnabled,InstanceTypes,Labels,LaunchTemplate,NodeRepairConfig,NodeRole,NodegroupName,ReleaseVersion,RemoteAccess,ScalingConfig,Subnets,Tags,Taints,UpdateConfig,Version,WarmPoolConfig
|
||||
AWS::ElastiCache::CacheCluster ConfigurationEndpoint,RedisEndpoint AZMode,AutoMinorVersionUpgrade,CacheNodeType,CacheParameterGroupName,CacheSubnetGroupName,ClusterName,Engine,EngineVersion,IpDiscovery,LogDeliveryConfigurations,NetworkType,NotificationTopicArn,NumCacheNodes,Port,PreferredAvailabilityZone,PreferredAvailabilityZones,PreferredMaintenanceWindow,SnapshotArns,SnapshotName,SnapshotRetentionLimit,SnapshotWindow,Tags,TransitEncryptionEnabled,VpcSecurityGroupIds
|
||||
AWS::ElastiCache::ReplicationGroup ConfigurationEndPoint,EffectiveDurability,PrimaryEndPoint,ReadEndPoint,ReaderEndPoint AtRestEncryptionEnabled,AuthToken,AutoMinorVersionUpgrade,AutomaticFailoverEnabled,CacheNodeType,CacheParameterGroupName,CacheSubnetGroupName,ClusterMode,DataTieringEnabled,Durability,Engine,EngineVersion,GlobalReplicationGroupId,IpDiscovery,KmsKeyId,LogDeliveryConfigurations,MultiAZEnabled,NetworkType,NodeGroupConfiguration,NotificationTopicArn,NumCacheClusters,NumNodeGroups,Port,PreferredCacheClusterAZs,PreferredMaintenanceWindow,PrimaryClusterId,ReplicasPerNodeGroup,ReplicationGroupDescription,ReplicationGroupId,SecurityGroupIds,SnapshotArns,SnapshotName,SnapshotRetentionLimit,SnapshotWindow,SnapshottingClusterId,Tags,TransitEncryptionEnabled,TransitEncryptionMode,UserGroupIds
|
||||
AWS::ElastiCache::ServerlessCache ARN,CreateTime,FullEngineVersion,Status CacheUsageLimits,ConnectionType,DailySnapshotTime,Description,Endpoint,Engine,FinalSnapshotName,KmsKeyId,MajorEngineVersion,NetworkType,ReaderEndpoint,SecurityGroupIds,ServerlessCacheName,SnapshotArnsToRestore,SnapshotRetentionLimit,SubnetIds,Tags,UserGroupId
|
||||
AWS::ElastiCache::SubnetGroup CacheSubnetGroupName,Description,SubnetIds,Tags
|
||||
AWS::ElastiCache::User Arn,Status AccessString,AuthenticationMode,Engine,NoPasswordRequired,Passwords,Tags,UserId,UserName
|
||||
|
||||
|
@@ -108,6 +108,7 @@ AWS::EFS::MountTarget EfsCfnProvisioner
|
||||
AWS::EKS::Cluster EksCfnProvisioner
|
||||
AWS::EKS::Nodegroup EksCfnProvisioner
|
||||
AWS::ElastiCache::CacheCluster ElastiCacheCfnProvisioner
|
||||
AWS::ElastiCache::ReplicationGroup ElastiCacheCfnProvisioner
|
||||
AWS::ElastiCache::ServerlessCache ElastiCacheServerlessCfnProvisioner
|
||||
AWS::ElastiCache::SubnetGroup ElastiCacheCfnProvisioner
|
||||
AWS::ElastiCache::User ElastiCacheCfnProvisioner
|
||||
|
||||
|
@@ -337,6 +337,21 @@ AWS::ElastiCache::CacheCluster PreferredAvailabilityZones accepted and ignored,
|
||||
AWS::ElastiCache::CacheCluster SnapshotArns accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::CacheCluster SnapshotName accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::CacheCluster TransitEncryptionEnabled accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup AutoMinorVersionUpgrade accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup DataTieringEnabled accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup Durability accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup GlobalReplicationGroupId accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup IpDiscovery accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup LogDeliveryConfigurations accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup NetworkType accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup NodeGroupConfiguration accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup NotificationTopicArn accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup PreferredCacheClusterAZs accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup PreferredMaintenanceWindow accepted and ignored
|
||||
AWS::ElastiCache::ReplicationGroup PrimaryClusterId accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup SnapshotArns accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup SnapshotName accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ReplicationGroup SnapshottingClusterId accepted and ignored, a warning is logged
|
||||
AWS::ElastiCache::ServerlessCache FinalSnapshotName accepted and ignored
|
||||
AWS::ElasticLoadBalancingV2::Listener AlpnPolicy accepted and ignored
|
||||
AWS::ElasticLoadBalancingV2::Listener ListenerAttributes accepted and ignored
|
||||
|
||||
|
@@ -98,7 +98,7 @@ type_order:
|
||||
AWS::RDS:
|
||||
[DBInstance, DBCluster, DBSubnetGroup, DBParameterGroup, DBClusterParameterGroup]
|
||||
AWS::ElastiCache:
|
||||
[CacheCluster, SubnetGroup, User, UserGroup, ServerlessCache]
|
||||
[CacheCluster, ReplicationGroup, SubnetGroup, User, UserGroup, ServerlessCache]
|
||||
AWS::Redshift:
|
||||
[Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterSecurityGroup, EventSubscription]
|
||||
AWS::RedshiftServerless:
|
||||
@@ -211,6 +211,7 @@ notes:
|
||||
AWS::RDS::DBInstance: starts a real container
|
||||
AWS::RDS::DBCluster: starts a real container
|
||||
AWS::ElastiCache::CacheCluster: 'starts a real container; modifying an existing cluster in place is not supported'
|
||||
AWS::ElastiCache::ReplicationGroup: 'starts a real container; modifying an existing group in place is not supported'
|
||||
AWS::ElastiCache::User: Tags are ignored
|
||||
AWS::ElastiCache::UserGroup: Tags are ignored
|
||||
AWS::ElastiCache::ServerlessCache: 'GetAtt uses the dotted Endpoint.* and ReaderEndpoint.* form'
|
||||
|
||||
Reference in new issue
Block a user