Skip to content

feat(cloudformation): provision ElastiCache cache clusters and subnet groups - #5307

Merged
pgermosen merged 3 commits into
floci-io:mainfrom
vuthehuyht:feat/4650-elasticache-cloudformation
Oct 10, 2026
Merged

pgermosen merged 3 commits into
floci-io:mainfrom
vuthehuyht:feat/4650-elasticache-cloudformation

Conversation

@vuthehuyht

@vuthehuyht vuthehuyht commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Provision the CacheCluster and SubnetGroup ElastiCache CloudFormation resource types so stacks create real resources instead of stubs or Resource type ... is not supported:

  • AWS::ElastiCache::CacheCluster and AWS::ElastiCache::SubnetGroup (ElastiCacheCfnProvisioner)

Ref returns the cluster id and the subnet group name. Fn::GetAtt returns RedisEndpoint.* for redis and valkey clusters and ConfigurationEndpoint.* for memcached. Create-only changes replace the resource and the displaced one is cleaned up after the update. DeleteStack removes clusters before subnet groups.

Two small service changes support the provisioner: modifyCacheSubnetGroup gains an overload that replaces the stored tags, and Memcached clusters record their NetworkType (default ipv4), as redis and valkey clusters already do, so a changed network type is detected as a replacement on both engines.

This PR was split from its first version, which also carried the serverless cache API and the User, UserGroup and ServerlessCache provisioners, following review feedback. They follow as separate PRs:

  • the serverless cache API (CreateServerlessCache, DescribeServerlessCaches, ModifyServerlessCache, DeleteServerlessCache)
  • AWS::ElastiCache::User and AWS::ElastiCache::UserGroup
  • AWS::ElastiCache::ServerlessCache, once the API is in

Known limit: a cache cluster is not modified in place on update (a warning is logged).

Part of #4650

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

Property names, required properties, create-only properties and readOnlyProperties follow the registry schemas in local/aws/cfn-resource-schemas/us-east-1/aws-elasticache-*.json. The integration test uses AWS SDK for Java v2 elasticache 2.55.11 (added as a test dependency), not the AWS CLI.

Checklist

  • ./mvnw test passes locally (the full suite was not run; the ElastiCache and CloudFormation tests that do not need Docker pass, except CfnSchemaCoverageTest, which fails locally on AWS::CertificateManager::Certificate Id because of the local schema directory, unrelated to this PR)
  • New or updated integration test added
  • Commit messages follow Conventional Commits
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

@hectorvent hectorvent added cloudformation AWS CloudFormation elasticache Amazon ElastiCache enhancement New feature or request labels Oct 8, 2026
@vuthehuyht
vuthehuyht marked this pull request as ready for review October 9, 2026 01:42
@qodo-code-review

qodo-code-review Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Provision ElastiCache clusters and subnet groups in CloudFormation

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Provision ElastiCache cache clusters and subnet groups as real CloudFormation resources.
• Expose Ref and engine-specific endpoints, with cleanup after create-only replacements.
• Add lifecycle tests and document the limit on in-place cluster updates.
Diagram

sequenceDiagram
    actor CFN as CloudFormation stack
    participant P as ElastiCache provisioner
    participant E as ElastiCache service
    participant M as Memcached service
    participant R as Replacement cleanup
    CFN->>P: Provision subnet group
    P->>E: Create or modify group
    E-->>P: Group name
    CFN->>P: Provision cache cluster
    alt Redis or Valkey
        P->>E: Create or find cluster
    else Memcached
        P->>M: Create or find cluster
    end
    P-->>CFN: Ref and endpoint attributes
    opt Replacing update
        P->>R: Record displaced ID
        CFN->>P: Complete update
        P->>R: Clean up old resource
        R->>P: Delegate deletion
    end
Loading
High-Level Assessment

The shared provisioner is appropriate: both resource types use the same CloudFormation lifecycle, while cluster operations dispatch to the existing engine-specific stores. Separate provisioners or a new shared cache store would add wiring or service changes without a clear benefit for this scope.

Files changed (11) +803 / -1

Enhancement (3) +271 / -1
ElastiCacheCfnProvisioner.javaProvision clusters and subnet groups through CloudFormation +262/-0

Provision clusters and subnet groups through CloudFormation

• Creates, reuses, replaces, and deletes both resource types through the existing ElastiCache services. Publishes physical IDs and engine-specific endpoint attributes, and delegates replacement lifecycle handling to ReplacementCleanup; in-place cluster changes are warned about rather than applied.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java

ElastiCacheMemcachedService.javaPersist Memcached cluster network type +2/-0

Persist Memcached cluster network type

• Stores the requested NetworkType on Memcached clusters, defaulting to ipv4, so replacement checks can compare it on updates.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java

ElastiCacheService.javaAllow subnet group updates to replace tags +7/-1

Allow subnet group updates to replace tags

• Adds a modifyCacheSubnetGroup overload that replaces stored tags when supplied. The existing overload retains its previous behavior.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java

Tests (5) +520 / -0
CfnProvisionerFixture.javaWire ElastiCache services into the test fixture +19/-0

Wire ElastiCache services into the test fixture

• Adds builder methods for both engine services and discovers the new provisioner when both are present.

src/test/java/io/github/hectorvent/floci/services/cloudformation/CfnProvisionerFixture.java

ElastiCacheCfnIntegrationTest.javaVerify stack-managed resources through the ElastiCache API +211/-0

Verify stack-managed resources through the ElastiCache API

• Tests subnet group creation, replacement, and deletion, plus cluster Ref and Redis endpoint outputs against the SDK. The container-backed cluster test skips when Docker is unavailable.

src/test/java/io/github/hectorvent/floci/services/cloudformation/ElastiCacheCfnIntegrationTest.java

ElastiCacheCfnProvisionerTest.javaCover provisioning and replacement behavior +286/-0

Cover provisioning and replacement behavior

• Tests engine routing, endpoint attributes, generated names, create-only changes, subnet group tags, replacement cleanup, and idempotent deletion.

src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisionerTest.java

getatt-attribute-gaps.tsvRecord endpoint object GetAtt exceptions +2/-0

Record endpoint object GetAtt exceptions

• Explains why whole ConfigurationEndpoint and RedisEndpoint objects are not exposed as scalar attributes; their dotted members are published instead.

src/test/resources/cloudformation/getatt-attribute-gaps.tsv

supported-resource-types.tsvRegister supported ElastiCache resource types +2/-0

Register supported ElastiCache resource types

• Maps CacheCluster and SubnetGroup to ElastiCacheCfnProvisioner for resource coverage checks.

src/test/resources/cloudformation/supported-resource-types.tsv

Documentation (2) +6 / -0
cloudformation.mdDocument ElastiCache CloudFormation support +1/-0

Document ElastiCache CloudFormation support

• Lists CacheCluster and SubnetGroup as supported resources and notes that clusters start containers but cannot be modified in place.

docs/services/cloudformation.md

cfn_resource_types.yamlAdd ElastiCache to generated resource documentation +5/-0

Add ElastiCache to generated resource documentation

• Configures ElastiCache ordering, its supported types, its display label, and the cache-cluster container and update limitation note.

tools/docs/cfn_resource_types.yaml

Other (1) +6 / -0
pom.xmlAdd the ElastiCache SDK for integration tests +6/-0

Add the ElastiCache SDK for integration tests

• Adds AWS SDK for Java v2's ElastiCache client as a test-scoped dependency.

pom.xml

@qodo-code-review

qodo-code-review Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

⚠️ 3 lower-priority findings omitted to fit the comment size limit; re-run the review or view the findings in the Qodo portal.

Grey Divider


Action required

1. Stacks accept clusters without node types ✓ Resolved
Description
createCluster passes a missing CacheNodeType through to the service instead of rejecting it as a
required property. A template containing only Engine reaches cluster creation, where the service
supplies a default node type and the stack accepts the invalid resource.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[169]

+                ctx.resolveOptional(props, "CacheNodeType"),
Relevance

●●● Strong

Required-property enforcement is consistent with accepted validation findings preventing backend
defaults from masking invalid templates.

PR-#4970

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new provisioner passes an optional node type to the service, and its new test demonstrates that
an Engine-only template is accepted. The service defaults a missing node type rather than rejecting
the request.

Rule 3865583: When validating request fields, reject invalid input at the boundary and add regression tests
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[161-170]
src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisionerTest.java[110-123]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1330-1339]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Cluster provisioning accepts a template without the required CacheNodeType property because the service supplies a default.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[91-99]
- src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisionerTest.java[110-123]

## Recommended Fix
Validate CacheNodeType before creating a cluster. Replace the test that accepts a missing node type with a regression test asserting rejection and no cluster creation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Failed updates leave subnet groups altered ✓ Resolved
Description
provisionSubnetGroup modifies a reused subnet group in place, but rollbackUpdate delegates to
replacement-only cleanup and cannot restore its previous description, subnets, or tags. If a later
resource fails during the stack update, the rollback marks this resource failed and leaves the
attempted configuration stored.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R229-231]

+        if (ctx.reusesPriorEntity(id)) {
+            group = elastiCacheService.modifyCacheSubnetGroup(id, description, subnetIds,
+                    ctx.resolveTags(props, "Tags"));
Relevance

●●● Strong

In-place updates lacking rollback restoration match multiple recent accepted rollback-state
findings.

PR-#4599
PR-#5009
PR-#4442

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The service persists the modified group immediately; unchanged physical IDs receive no replacement
rollback record, and the stack engine treats a false rollback result as a failure.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[2192-2212]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ReplacementCleanup.java[58-103]
src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java[2044-2100]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
In-place subnet group updates persist immediately, but replacement-only rollback returns false and cannot restore their previous state.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[81-89]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[222-236]
## Recommended Fix
Snapshot the existing subnet group's description, subnet IDs, and tags before an in-place modification; restore that state in rollbackUpdate and clear the snapshot after a committed update. Add a stack test in which a later resource fails.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Stacks accept oversized cache names ✓ Resolved
Description
provisionCacheCluster and provisionSubnetGroup pass explicit names to stablePhysicalName,
which applies their length limits only to generated names. An explicit cluster name over 50
characters or subnet-group name over 255 characters reaches creation unchanged, and the service does
not enforce those maximum lengths.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[121]

+            id = ctx.stablePhysicalName(explicitName, r.getLogicalId(), CLUSTER_ID_MAX_LENGTH, true);
Relevance

●●● Strong

Explicit-name length validation matches recent accepted boundary-validation fixes.

PR-#4970
PR-#4830

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new provisioner declares maximum lengths but relies on a helper that returns explicit names
unchanged. Neither downstream creation path checks those maximum lengths.

Rule 3865583: When validating request fields, reject invalid input at the boundary and add regression tests
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[35-37]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[119-121]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[222-224]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ProvisionContext.java[151-164]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[2268-2278]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Explicit cache-cluster and subnet-group names bypass the length limits used for generated names.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[117-122]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[222-225]
- src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisionerTest.java[168-181]

## Recommended Fix
Reject explicit names exceeding the respective resource limits before calling either create service. Add tests asserting rejection and no resource creation for each oversized name.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View high (6)
4. Encrypted clusters reject unauthenticated clients ✓ Resolved
Description
createCluster translates TransitEncryptionEnabled into AuthMode.IAM, although that property
does not supply an authentication mode or token. When a stack enables transit encryption, the
cluster proxy requires credentials and routes authentication through its signature validator instead
of allowing the otherwise unauthenticated connection.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[177]

+                transitEncryption ? AuthMode.IAM : AuthMode.NO_AUTH,
Relevance

●●● Strong

Authentication behavior mismatches are accepted when encryption or mode selection changes proxy
access semantics.

PR-#4536
PR-#5059

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new provisioner selects IAM solely from the encryption flag; the cluster service persists that
mode, and the proxy requires authentication whenever its current mode is not NO_AUTH.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[168-178]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1371-1396]
src/main/java/io/github/hectorvent/floci/services/elasticache/proxy/ElastiCacheAuthProxy.java[34-43]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
CloudFormation transit encryption currently enables IAM authentication on the cache proxy.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[168-178]
- src/main/java/io/github/hectorvent/floci/services/elasticache/proxy/ElastiCacheAuthProxy.java[34-43]
## Recommended Fix
Do not derive `AuthMode.IAM` from `TransitEncryptionEnabled`. Preserve the intended no-auth behavior unless an independently supported authentication setting requests otherwise, and test connections to a cluster created with transit encryption enabled.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Stack updates fail for mixed-case serverless names ✓ Resolved
Description
ElastiCacheServerlessCfnProvisioner.provision passes the raw ServerlessCacheName to
ctx.reusesPriorEntity(name), but the service lowercases the name used as the cache’s physical ID.
When the template name contains uppercase letters, the case-sensitive comparison misses the prior
cache, so each subsequent UpdateStack takes the create path and fails with
ServerlessCacheAlreadyExistsFault.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[R49-53]

+        if (ctx.reusesPriorEntity(name)) {
+            cache = modify(name, props, ctx);
+        } else {
+            cache = create(name, engine, props, ctx);
+        }
Relevance

●●● Strong

Recent accepted findings specifically address normalized physical names bypassing reuse checks and
causing duplicate-resource failures.

PR-#4734
PR-#3695

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The provisioner compares the unnormalized template name with the prior physical ID. The service
accepts uppercase letters but normalizedName applies name.toLowerCase(Locale.ROOT), and the
provisioner uses the stored lowercase name as the physical ID. Because reusesPriorEntity uses
case-sensitive equals, a name such as Example cannot match example; the create path then
encounters the existing lowercase cache key.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[292-297]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[76-79]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ProvisionContext.java[187-189]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[41-55]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[57-77]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The serverless provisioner compares the raw `ServerlessCacheName` with a prior physical ID that the service stores in lowercase. A mixed-case name therefore makes a later stack update attempt to create the cache again, failing with `ServerlessCacheAlreadyExistsFault`.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[41-55]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[292-297]

## Recommended Fix
After validating the resolved name, normalize it consistently with the service using `name.toLowerCase(Locale.ROOT)` before checking `ctx.reusesPriorEntity(name)` and before invoking create or modify. Add a create-then-update stack test with a mixed-case `ServerlessCacheName`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Failed cache creation leaves a group linked ✓ Resolved
Description
createServerlessCache puts backing-cache deletion and user-group detachment in one cleanup block,
so a deletion exception skips detachment. If a step after backing creation fails and backing
deletion also throws, the user group retains its association even though cache creation failed.
Code

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[R120-124]

+                    if (backing != null) {
+                        deleteBacking(engine, backing.getCacheClusterId());
+                    }
+                    if (attached) {
+                        groups.detachServerlessCache(request.userGroupId(), name);
Relevance

●●● Strong

Accepted precedents favor independent best-effort cleanup when one resource cleanup can mask
another.

PR-#4728
PR-#5306

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new creation path attaches the group before creating the backing cache. Its catch block calls
deleteBacking before detachServerlessCache inside the same try block, and the cleanup catch only
records the exception; a deletion failure therefore bypasses detachment.

Rule 3865612: Mutating operations must clean up created resources if a later step fails
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[79-93]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[118-129]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A failure while deleting a newly created backing cache prevents the failed creation path from detaching its user group.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[118-129]

## Recommended Fix
Attempt backing deletion and group detachment independently, preserving the original exception and recording cleanup failures as suppressed. Add a regression test that makes a post-creation step fail and backing deletion throw, then checks that detachment was attempted.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


7. Stack updates fail for mixed-case user group ids ✓ Resolved
Description
provisionUserGroup calls ctx.reusesPriorEntity(groupId) with the raw template UserGroupId. The
stored physical id is lowercase, because createUserGroup normalizes it with
normalizeUserGroupId. When UserGroupId contains any uppercase letter (e.g. MyUsers), the
case-sensitive check is false on every UpdateStack, so the provisioner calls createUserGroup again
and the update fails with UserGroupAlreadyExists.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R288-290]

+        ElastiCacheUserGroup group;
+        if (ctx.reusesPriorEntity(groupId)) {
+            ElastiCacheUserGroup existing = elastiCacheService.getUserGroup(groupId);
Relevance

●●● Strong

Normalization mismatches causing duplicate creation have repeatedly been accepted as correctness
bugs.

PR-#4734
PR-#3695

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
reusesPriorEntity uses priorPhysicalId.equals(name), which is case-sensitive. The physical id is
set from group.getUserGroupId(), which createUserGroup lowercases, and createUserGroup throws
if that lowercase id already exists.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ProvisionContext.java[187-189]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1915-1930]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[2106-2112]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[277-307]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`provisionUserGroup` compares the raw `UserGroupId` with the prior physical id, but the service stores the id in lowercase. A mixed-case id makes every update try to create the group again, and the update fails with `UserGroupAlreadyExists`.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[277-290]

## Recommended Fix
Right after the required-property check, normalize the id with `groupId = groupId.toLowerCase(Locale.ROOT);`, then use that value for `reusesPriorEntity`, `getUserGroup` and `createUserGroup`. Add a unit test that updates a stack whose `UserGroupId` is mixed-case.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Memcached clusters are replaced on every update ✓ Resolved
Description
createOnlyChanged treats any non-null template NetworkType that differs from
prior.getNetworkType() as a change to a create-only property.
ElastiCacheMemcachedService.provisionCacheCluster never calls setNetworkType, so for a memcached
cluster that value is always null. For a memcached CacheCluster that declares NetworkType, every
UpdateStack either generates a new cluster id and deletes the old cluster with its data (no
ClusterName), or fails with "requires a new ClusterName" (with ClusterName).
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R113-116]

+        boolean createOnlyChanged = prior != null
+                && (!engine.equalsIgnoreCase(prior.getEngine())
+                || !Objects.equals(subnetGroup, prior.getCacheSubnetGroupName())
+                || (networkType != null && !networkType.equals(prior.getNetworkType())));
Relevance

●●● Strong

Accepted update-path precedents favor applying or correctly comparing fields rather than repeatedly
replacing resources.

PR-#4971
PR-#5009

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The redis path stores the network type (it defaults to ipv4). The memcached path sets node type,
subnet group, security groups, AZ and region, but never sets the network type, so the comparison
sees null on every update.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[141-169]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1456-1457]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[117-126]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The memcached service never stores `NetworkType`, so `createOnlyChanged` is true on every update of a memcached cluster whose template sets `NetworkType`. The cluster is replaced each time, or the update fails when `ClusterName` is set.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[112-116]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[141-169]

## Recommended Fix
Either store the network type in `ElastiCacheMemcachedService.provisionCacheCluster` (`cluster.setNetworkType(request.networkType() != null && !request.networkType().isBlank() ? request.networkType() : "ipv4")`), or have the provisioner compare `NetworkType` only when `prior.getNetworkType() != null`. Add a test that updates a memcached cluster with `NetworkType` unchanged and asserts its physical id stays the same.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Cache subnet and key changes never apply ✓ Resolved
Description
ElastiCacheServerlessCfnProvisioner.modify only warns when SubnetIds or KmsKeyId differs, then
updates the existing physical cache. An update changing either create-only value completes while
modifyServerlessCache leaves both stored values untouched.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[R93-96]

+        if ((!subnets.isEmpty() && !subnets.equals(existing.getSubnetIds()))
+                || (kms != null && !kms.equals(existing.getKmsKeyId()))) {
+            LOG.warnv("ElastiCache serverless cache {0}: SubnetIds and KmsKeyId are create-only, changes are ignored", name);
+        }
Relevance

●●● Strong

Accepted precedents require changed fields to reach update APIs; warning while silently ignoring
changes is treated as incorrect.

PR-#4971
PR-#5009

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The warning is followed by a modify request without subnet or KMS fields, and the service's modify
implementation changes neither field.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[89-111]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[165-193]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Serverless cache subnet and encryption-key changes are acknowledged but silently discarded during stack updates.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[41-53]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[89-111]
## Recommended Fix
Detect changes to either create-only field before choosing the reuse path. Create a replacement cache under a new name when possible, record it through the existing replacement cleanup lifecycle, and reject an impossible same-name replacement rather than reporting success.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

10. Memcached accepts missing subnet groups ✓ Resolved
Description
createCluster passes CacheSubnetGroupName to the Memcached service, whose creation path stores
the name without checking that the group exists. A Memcached stack can therefore complete with a
cluster that reports a subnet group that cannot be described, whereas the Redis creation path
rejects the same input.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R186-188]

+        return "memcached".equalsIgnoreCase(engine)
+                ? memcachedService.createCacheCluster(request)
+                : elastiCacheService.createCacheCluster(request);
Relevance

●●● Strong

Referenced-resource existence validation is a clear correctness requirement, with accepted
ElastiCache backend validation fixes.

PR-#4536
PR-#5053

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new route reaches a Memcached create path with no existence check; the Redis path explicitly
validates the same request field and defines its not-found fault.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[73-145]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1236-1255]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1271-1283]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
CloudFormation routes Memcached clusters to a creation path that accepts nonexistent subnet groups.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[175-188]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[73-112]
## Recommended Fix
Validate a supplied subnet-group name before starting or persisting the Memcached cluster, returning the same not-found fault as Redis. Add a provisioner test with a nonexistent group.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


11. Renames orphan caches from subnet groups ✓ Resolved
Description
delete removes a displaced subnet group through deleteCacheSubnetGroup, which checks only
whether the group exists and not whether a cluster still names it. If a stack renames an explicitly
named group while a cluster uses its old literal name, replacement cleanup deletes the old group and
leaves the live cluster pointing to it.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R252-253]

+            case SUBNET_GROUP -> CfnDeletes.safeDelete("ElastiCache subnet group", physicalId,
+                    () -> elastiCacheService.deleteCacheSubnetGroup(physicalId), "CacheSubnetGroupNotFoundFault");
Relevance

●●● Strong

Replacement cleanup must preserve live-resource references; recent accepted deletion and
replacement-safety findings support this.

PR-#3950
PR-#4511

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Replacement cleanup invokes this deletion path, but the service deletes any existing group without
checking cluster references; the Redis cluster record retains its requested subnet-group name.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[222-253]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1390-1397]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[2216-2228]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Subnet-group replacement cleanup can delete a group still named by a live cache cluster.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[248-253]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[2216-2228]
## Recommended Fix
Before deleting a subnet group, check the Redis and Memcached cluster stores for references and reject deletion when it remains in use. Test a group rename with a cluster referring to the old name literally.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


12. Memcached cluster tags vanish on creation ✓ Resolved
Description
createCluster supplies the resolved Tags map to both engines, but ElastiCacheMemcachedService
never copies that map onto the cluster it stores. When a template tags a Memcached cluster, the
stack completes while its tag-list API returns no tags.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R184-187]

+                ctx.region(),
+                ctx.resolveTags(props, "Tags"));
+        return "memcached".equalsIgnoreCase(engine)
+                ? memcachedService.createCacheCluster(request)
Relevance

●●● Strong

Lost tags are a concrete persisted-state bug; recent ElastiCache and update-state findings were
accepted.

PR-#5053
PR-#4599

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The model starts with an empty tag map, the Memcached creation code never sets it, and the tag-list
handler does not obtain tags from a Memcached cluster.

src/main/java/io/github/hectorvent/floci/services/elasticache/model/CacheCluster.java[35-38]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[131-162]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java[768-798]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Tags passed through the CloudFormation Memcached creation request are discarded before the cluster is stored.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[181-188]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedService.java[131-162]
## Recommended Fix
Copy request tags onto the Memcached cluster during provisioning and ensure the tag-list API reads them. Cover tagged Memcached stack creation in a test.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View medium (3)
13. Engine switch leaves the old cluster's endpoint readable ✓ Resolved
Description
putEndpointAttributes adds the current engine’s endpoint keys to attributes copied from the prior
resource without removing the other engine’s keys, and its null-endpoint return leaves both prefixes
untouched. When an unnamed cluster is replaced across Redis/Valkey and Memcached engine families,
Fn::GetAtt can still resolve the displaced cluster’s address and port after cleanup deletes it.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R191-201]

+    private void putEndpointAttributes(StackResource r, CacheCluster cluster) {
+        Endpoint endpoint = cluster.getConfigurationEndpoint();
+        if (endpoint == null) {
+            return;
+        }
+        // CloudFormation exposes a memcached cluster through ConfigurationEndpoint and a
+        // redis or valkey one through RedisEndpoint.
+        String prefix = "memcached".equalsIgnoreCase(cluster.getEngine())
+                ? "ConfigurationEndpoint" : "RedisEndpoint";
+        r.getAttributes().put(prefix + ".Address", endpoint.address());
+        r.getAttributes().put(prefix + ".Port", String.valueOf(endpoint.port()));
Relevance

●●● Strong

Stale attributes surviving replacement closely matches accepted CloudFormation attribute-cleanup
precedent.

PR-#4451
PR-#4806

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
copyResource carries prior attributes into the resource supplied to the provisioner, and
ReplacementCleanup.record identifies attributesBefore as those prior attributes. An engine
change triggers createOnlyChanged, generating a new id and creating a replacement, but
putEndpointAttributes writes only the selected engine’s prefix without clearing the other; the
resulting attribute map remains available for intrinsic resolution.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[109-122]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[191-202]
src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java[2177-2189]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ReplacementCleanup.java[70-90]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CfnResourceDispatcher.java[78-89]
src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java[1527-1532]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`putEndpointAttributes` retains endpoint attributes from the previous engine family when a cluster is replaced, allowing lookups to resolve the deleted cluster’s endpoint.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[191-202]

## Recommended Fix
At the start of `putEndpointAttributes`, before the null-endpoint early return, remove `RedisEndpoint.Address`, `RedisEndpoint.Port`, `ConfigurationEndpoint.Address`, and `ConfigurationEndpoint.Port` from `r.getAttributes()`. Then write only the keys for the current engine. Add a unit test that replaces an unnamed Redis cluster with a Memcached cluster and verifies that the old `RedisEndpoint.*` keys are absent and lookup of an old attribute name does not resolve the displaced endpoint.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


14. Changing a user group's engine fails the update ✓ Resolved
Description
On an in-place update, provisionUserGroup throws InvalidParameterValue whenever the template
Engine differs from the stored engine, treating it as create-only. CloudFormation documents
Engine as "Update requires: No interruption", and modifyUserGroup already accepts an engine. A
template that moves a user group from redis to valkey therefore rolls back instead of modifying the
group.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[R291-294]

+            if (!engine.equalsIgnoreCase(existing.getEngine())) {
+                throw new AwsException("InvalidParameterValue",
+                        "Engine of user group " + groupId + " is create-only; use a new UserGroupId to change it", 400);
+            }
Relevance

●●● Strong

The repository accepts findings where documented updatable properties are rejected instead of passed
through existing modification APIs.

PR-#4971
PR-#5009

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The provisioner rejects an engine change, then calls `modifyUserGroup(groupId, toAdd, toRemove,
null)` without the engine, even though the service method validates and applies an engine change
itself. The AWS template reference lists Engine for UserGroup as updatable without interruption.

src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java[1952-1974]
🌐 Engine: The current supported values are valkey and redis. Required: Yes. Update requires: No interruption

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`provisionUserGroup` treats `Engine` as create-only and fails the update, but AWS updates it in place and `ElastiCacheService.modifyUserGroup` already supports an engine change.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheCfnProvisioner.java[289-301]

## Recommended Fix
Remove the engine-mismatch exception. Compute `boolean engineChanged = !engine.equalsIgnoreCase(existing.getEngine());`, call `modifyUserGroup(groupId, toAdd, toRemove, engineChanged ? engine : null)` when members or the engine changed, and keep returning `existing` otherwise. Add a test that switches a user group from redis to valkey on update.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


15. Removed security groups stay on caches ✓ Resolved
Description
ElastiCacheServerlessCfnProvisioner.modify converts an empty resolved SecurityGroupIds list to
null. When a stack removes its previously specified groups or sets the list to empty,
modifyServerlessCache interprets that null as no update and retains the old groups.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[105]

+                securityGroupIds.isEmpty() ? null : securityGroupIds,
Relevance

●●● Strong

Recent accepted precedents require preserving explicit empty values so removed configuration is
cleared during updates.

PR-#5008
PR-#5218

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The provisioner passes null for an empty list, while the service updates security groups only for a
non-null request value.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[97-110]
src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[158-183]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
CloudFormation cannot clear a serverless cache's security-group list because an empty list becomes the service's no-change marker.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ElastiCacheServerlessCfnProvisioner.java[97-110]
- src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServerlessService.java[158-183]
## Recommended Fix
Distinguish an omitted or intentionally cleared property from a no-op update, passing an empty list when the desired security-group set is empty. Add a stack-update test starting with a nonempty list.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 8 rules
✅ Cross-repo context — repo relationships
Review mode: Auto: 🧠 Deep: Complex multi-path provisioning warrants redundant review; confidence 3/5.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vuthehuyht thanks, this is a big one. The red CI comes from the PR itself, in two places.

Checkstyle now enforces import order, and two of the new tests break it: in ElastiCacheCfnIntegrationTest, ElastiCacheException belongs before UserGroupNotFoundException, and in ElastiCacheCfnProvisionerTest the static JUnit import belongs before the Mockito ones.

AwsQueryActionRoutingParityTest wants ElastiCacheServerlessQueryHandler registered, and CreateServerlessCache, DeleteServerlessCache, DescribeServerlessCaches and ModifyServerlessCache added to the ElastiCache set in AwsQueryController. Without that, a request that carries no credential scope routes those actions to SQS.

@pgermosen pgermosen added the waiting-author Review posted; waiting on the PR author to respond label Oct 9, 2026

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vuthehuyht thanks, both are fixed and CI is green.

This bundles two features, though: CloudFormation support for the four types the service already has, and a new serverless cache API (four operations, hidden backing clusters, and its own auth path in the proxy), which is about half the diff and changes the existing cluster code. Could the serverless API go in its own PR with its own issue, so this one keeps the CacheCluster, SubnetGroup, User and UserGroup provisioners? The ServerlessCache provisioner can follow once the API is in.

@vuthehuyht
vuthehuyht marked this pull request as draft October 9, 2026 03:33
@vuthehuyht
vuthehuyht force-pushed the feat/4650-elasticache-cloudformation branch from 6b8878d to 4375bb4 Compare October 9, 2026 04:51
@vuthehuyht vuthehuyht changed the title feat(cloudformation): provision the ElastiCache resource types feat(cloudformation): provision ElastiCache cache clusters and subnet groups Oct 9, 2026
@vuthehuyht
vuthehuyht requested a review from pgermosen October 9, 2026 17:24
@vuthehuyht
vuthehuyht marked this pull request as ready for review October 10, 2026 02:26
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 4375bb4

@vuthehuyht
vuthehuyht force-pushed the feat/4650-elasticache-cloudformation branch from f56a668 to 3f59ae3 Compare October 10, 2026 03:16

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vuthehuyht thanks for splitting it, this is much easier to follow.

The new in-use refusal throws CacheSubnetGroupInUseFault, but the model's wire code for that error is CacheSubnetGroupInUse, without the suffix, so SDKs won't map it to their exception; the service and provisioner tests pin the suffixed code too. The Memcached requireCacheSubnetGroup is also a copy of the private one in ElastiCacheService, so one shared helper taking the subnet-group store would cover both.

The registry schema also requires NumCacheNodes on CacheCluster and Description on SubnetGroup, which could be checked the way CacheNodeType now is.

… groups

Add AWS::ElastiCache::CacheCluster and AWS::ElastiCache::SubnetGroup provisioners with Ref, Fn::GetAtt endpoint attributes, create-only replacement and update handling. Subnet group updates now carry tags through modifyCacheSubnetGroup, and Memcached clusters record their network type.
@vuthehuyht
vuthehuyht force-pushed the feat/4650-elasticache-cloudformation branch from 42faba3 to ab8dbc9 Compare October 10, 2026 05:57
@vuthehuyht
vuthehuyht requested a review from pgermosen October 10, 2026 07:37

@pgermosen pgermosen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vuthehuyht thanks, that covers all three: the wire code, the shared subnet-group check and the required properties. Good to go.

@pgermosen pgermosen removed the waiting-author Review posted; waiting on the PR author to respond label Oct 10, 2026
@pgermosen
pgermosen merged commit 475d230 into floci-io:main Oct 10, 2026
25 checks passed
@vuthehuyht
vuthehuyht deleted the feat/4650-elasticache-cloudformation branch October 11, 2026 13:31
omatheusmesmo pushed a commit to omatheusmesmo/floci that referenced this pull request Oct 12, 2026
… groups (floci-io#5307)

* feat(cloudformation): provision ElastiCache cache clusters and subnet groups

Add AWS::ElastiCache::CacheCluster and AWS::ElastiCache::SubnetGroup provisioners with Ref, Fn::GetAtt endpoint attributes, create-only replacement and update handling. Subnet group updates now carry tags through modifyCacheSubnetGroup, and Memcached clusters record their network type.

* fix(elasticache): validate cluster name, rollback subnet groups and preserve memcached tags

* fix(elasticache): align in-use error wire code and enforce schema required properties
Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
@hectorvent

Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cloudformation AWS CloudFormation elasticache Amazon ElastiCache enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants