Skip to content

feat(cloudformation): support Redshift snapshot restores - #6395

Merged
pgermosen merged 4 commits into
floci-io:mainfrom
vuthehuyht:feat/redshift-cfn-snapshot-restore
Oct 24, 2026
Merged

pgermosen merged 4 commits into
floci-io:mainfrom
vuthehuyht:feat/redshift-cfn-snapshot-restore

Conversation

@vuthehuyht

Copy link
Copy Markdown
Contributor

Summary

Honor SnapshotIdentifier when creating AWS::Redshift::Cluster: restore the snapshot's SQL dump instead of creating an empty database, inherit its admin credentials, and support ManageMasterPassword with a new Secrets Manager secret.

Changing, adding, or removing the snapshot replaces the cluster through the existing cleanup and rollback mechanism. Updates with an unchanged snapshot preserve the cluster and its data. Keep endpoint references and managed-secret attributes accurate, and pass cluster ARNs when applying CloudFormation tags.

Type of change

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

AWS Compatibility

  • Reuses the existing Redshift snapshot restore and AWS Query/XML paths; no new endpoints or configuration.
  • Validates Redshift management responses with AWS SDK for Java v2 2.55.14, and CloudFormation behavior through Query requests.
  • Adds tests for inherited and managed credentials, replacement/rollback, stable IDs after replacement, tagging failures, and exact endpoint attributes. The Docker test restores SQL rows after deleting the source cluster and verifies that an unchanged-snapshot update preserves later writes.
  • AWS CLI and live AWS comparison were not run. Existing PostgreSQL-backed emulator limitations remain documented.

Validation:

  • 299 unit tests passed: RedshiftClusterCfnProvisionerTest, RedshiftServiceTest, RedshiftQueryHandlerTest.
  • 6 integration tests passed: RedshiftSnapshotCfnIntegrationTest, RedshiftFinalSnapshotIntegrationTest.
  • 3 tests in RedshiftClusterCfnIntegrationTest skipped because Docker is unavailable. The non-Docker integration run used -Dfloci.docker.docker-host=tcp://127.0.0.1:1 to avoid Windows named-pipe retry delays; container operations are mocked in those tests.
  • Checkstyle, make docs-check, partition literal check, and git diff --check passed.

Checklist

  • ./mvnw test passes locally
  • 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).

The full test suite was not run; validation was limited to the focused suites above.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Support Redshift snapshot restores in CloudFormation

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Restore Redshift clusters from snapshot SQL dumps, inheriting credentials or generating managed
 passwords.
• Replace clusters when snapshot settings change; preserve data when the snapshot stays unchanged.
• Cover restoration, rollback, references, and tagging with tests and updated documentation.
Diagram

graph TD
  T["CFN template"] --> P["Cluster provisioner"] --> D{"Replacement needed?"} -->|yes| R["Create or restore"] --> C["Redshift cluster"]
  D -->|no| U["Modify cluster"] --> C
  S["Snapshot SQL dump"] -->|when restoring| R
  R -->|managed password| M["Secrets Manager"]
Loading
High-Level Assessment

Reusing Redshift's snapshot-restore service and CloudFormation's existing replacement and rollback mechanism keeps the change aligned with current resource lifecycle behavior. A separate restoration path would duplicate those mechanisms without a clear benefit.

Files changed (7) +670 / -16

Enhancement (2) +111 / -14
RedshiftClusterCfnProvisioner.javaProvision clusters from snapshots and track replacement state +70/-8

Provision clusters from snapshots and track replacement state

• Routes snapshot-backed creation through Redshift restoration, applies optional settings, and tracks template identifiers and snapshot properties for replacement decisions. Cleans up failed restores, refreshes secret attributes, and passes cluster ARNs for tagging.

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

RedshiftService.javaExtend snapshot restore with managed credentials +41/-6

Extend snapshot restore with managed credentials

• Adds a restore path that records the subnet group and can rotate the inherited password into a new Redshift-owned Secrets Manager secret. Reuses secret creation logic and deletes the restored cluster if post-restore setup fails.

src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java

Tests (4) +532 / -1
RedshiftClusterCfnIntegrationTest.javaVerify SQL rows survive CloudFormation restoration +89/-0

Verify SQL rows survive CloudFormation restoration

• Adds a Docker-backed test that restores rows after deleting the source cluster, checks stack references and endpoint outputs, and confirms an unchanged-snapshot update preserves subsequent writes.

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

RedshiftSnapshotCfnIntegrationTest.javaExercise snapshot stacks through AWS Query APIs +149/-0

Exercise snapshot stacks through AWS Query APIs

• Adds a container-mocked integration test covering dump restoration, exact endpoint outputs, and reuse of the cluster on an unchanged-snapshot update.

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

RedshiftClusterCfnProvisionerTest.javaCover snapshot provisioning and replacement decisions +233/-1

Cover snapshot provisioning and replacement decisions

• Tests validation, managed-secret attributes, unchanged updates, snapshot changes and removal, rollback, stable replacement IDs, and failure cleanup. Updates the tagging assertion to require a cluster ARN.

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

RedshiftServiceTest.javaTest managed-password snapshot restoration +61/-0

Test managed-password snapshot restoration

• Verifies the restored subnet group, generated password, secret contents, and database password change. Confirms secret-creation failure removes the restored cluster while retaining the snapshot.

src/test/java/io/github/hectorvent/floci/services/redshift/RedshiftServiceTest.java

Documentation (1) +27 / -1
redshift.mdDocument CloudFormation snapshot restoration +27/-1

Document CloudFormation snapshot restoration

• Explains inherited and managed credentials, replacement versus in-place updates, references, and local SQL-dump limitations. Adds a snapshot-backed cluster template example.

docs/services/redshift.md

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Restored clusters miss managed secrets ✓ Resolved
Description
provisionCluster reuses a cluster when its snapshot identifier is unchanged, but that update path
calls modifyCluster without reconciling ManageMasterPassword. Changing the property from false
to true completes without creating a secret, while changing it from true to false leaves the
existing managed secret attached.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[R142-143]

+        } else if (ctx.isUpdate() && sameTemplateIdentifier) {
+            id = ctx.priorPhysicalId();
Relevance

●●● Strong

Recent accepted precedents favor reconciling managed-secret state during in-place updates.

PR-#5553
PR-#5420

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new same-ID branch takes unchanged-snapshot updates to modifyCluster, which only performs
credential work when given a nonblank password. Secret creation occurs in the restore/create
helpers, and the provisioner exposes whichever secret ARN remains on the returned cluster.
CloudFormation documents this property as updateable without interruption.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[125-159]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[763-790]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1217-1224]
🌐 ManageMasterPassword has an update requirement of 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
A restored cluster with an unchanged snapshot identifier ignores subsequent changes to ManageMasterPassword.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[142-159]
- src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1206-1234]
## Recommended Fix
Add an in-place service operation for enabling and disabling managed credentials, including secret creation or removal and cluster metadata updates. Invoke it when the requested mode differs from the existing cluster, without replaying the snapshot; test both transitions.

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



Remediation recommended

2. Removed cluster tags remain attached ✓ Resolved
Description
provisionCluster now passes a usable ARN to createTags, but never calls deleteTags for keys
removed from the desired tag map. On a subsequent stack update, createTags merges remaining keys
into existing tags, and removing Tags entirely skips tagging altogether, so omitted keys remain on
the cluster.
Code

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

+                String arn = AwsArnUtils.Arn.of("redshift", ctx.region(), ctx.accountId(), "cluster:" + id).toString();
+                redshiftService.createTags(arn, tags);
Relevance

●●● Strong

Recent accepted tag precedents require removing stale tag records and reconciling tag state.

PR-#5973
PR-#4563

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The ARN change makes cluster tagging work, but the provisioner only applies a nonempty desired set.
createTags uses putAll without removing old keys, whereas deleteTags is the separate removal
API and is not called here.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[184-200]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1909-1920]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ProvisionContext.java[194-225]

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 updates cannot remove tags from Redshift clusters after the ARN-based tagging path applies them.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[184-199]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ProvisionContext.java[194-230]
## Recommended Fix
On updates to an existing cluster, read its current tags, compute keys absent from the resolved desired tags, and call deleteTags with the cluster ARN before applying desired tags. Perform this reconciliation even when the desired map is empty; test removal of one tag and all tags.

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


3. Cluster edits change inherited passwords ✓ Resolved
Description
provisionCluster ignores a template MasterUserPassword during snapshot creation but passes that
same value to modifyCluster when a later edit reuses the restored cluster. If the template
includes a password different from the snapshot's, editing an unrelated cluster property such as
NodeType changes the database and proxy password even though the password property did not change.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[R142-143]

+        } else if (ctx.isUpdate() && sameTemplateIdentifier) {
+            id = ctx.priorPhysicalId();
Relevance

●●● Strong

Accepted precedents require preserving and correctly applying mutable credential state during
updates.

PR-#5422
PR-#5553

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Restore selects the snapshot password and starts the container and proxy with it. A same-snapshot
update takes the reuse path, where modifyCluster applies any supplied template password to both
the database user and proxy; CloudFormation invokes that path when the cluster resource's other
properties change.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[125-159]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1260-1288]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[763-778]
src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java[2009-2017]

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

## Issue description
An unrelated update to a snapshot-restored cluster applies a template password that initial restoration deliberately ignored.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[142-159]
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[203-214]
## Recommended Fix
Track the previously declared password securely, or otherwise detect whether the password property actually changed, and pass a password to modifyCluster only for an explicit password update. Preserve snapshot credentials on updates to unrelated properties; add a regression test for that sequence.

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


4. Parameter groups with Tags still fail to deploy ✓ Resolved
Description
The PR switches cluster tagging to pass a Redshift ARN, but provisionParameterGroup still calls
redshiftService.createTags(id, tags) with the bare group name, and resolveTagHandle rejects any
name that does not start with arn: with InvalidParameterValue. As a result, any
AWS::Redshift::ClusterParameterGroup that declares Tags fails to create or update, and the
mocked unit test that checks the bare id hides the failure.
Code

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

+                String arn = AwsArnUtils.Arn.of("redshift", ctx.region(), ctx.accountId(), "cluster:" + id).toString();
+                redshiftService.createTags(arn, tags);
Relevance

●●● Strong

ARN validation and resource-specific ARN construction are consistently accepted correctness
requirements.

PR-#5840
PR-#5373

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
createTags resolves the resource through resolveTagHandle, which throws unless the name is an
ARN. The cluster call was fixed to build an ARN, but the parameter group call at line 287 still
passes the bare id. The unit test at line 125 checks that bare-id call on a mock, so the real
failure never shows up in tests.

src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[2020-2026]
src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[284-288]
src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisionerTest.java[120-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
`provisionParameterGroup` calls `redshiftService.createTags(id, tags)` with a bare name. `RedshiftService.resolveTagHandle` only accepts Redshift ARNs, so any parameter group template with Tags fails.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[284-288]
- src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisionerTest.java[120-126]

## Recommended Fix
Build `AwsArnUtils.Arn.of("redshift", ctx.region(), ctx.accountId(), "parametergroup:" + id).toString()` and pass it to `createTags`, the same way the cluster path does. Update the unit test to expect the ARN.

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


View medium (2)
5. Restored secrets keep the old key ✓ Resolved
Description
provisionCluster forwards MasterPasswordSecretKmsKeyId only to the initial restore call, not to
the same-cluster update path. Changing the key while retaining the snapshot and managed-password
setting leaves the existing secret and cluster metadata on the old key despite a successful stack
update.
Code

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[R157-159]

+        } else if (snapshotIdentifier != null) {
+            cluster = redshiftService.restoreFromClusterSnapshot(id, snapshotIdentifier, nodeType, subnetGroup,
+                    manageMasterPassword, ctx.resolveOptional(props, "MasterPasswordSecretKmsKeyId"), ctx.region());
Relevance

●●● Strong

Recent accepted precedent specifically addresses persisted managed-secret KMS key state.

PR-#5420

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
For an unchanged snapshot, the prior ID is reused and modifyCluster receives no KMS-key argument.
The key is set only during managed-secret creation, so the newly supported managed snapshot restore
has no path to apply a later key change. CloudFormation lists this property as updateable without
interruption.

src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[142-159]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[352-361]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[744-790]
🌐 MasterPasswordSecretKmsKeyId has an update requirement of 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
Changing the managed secret's KMS key on a snapshot-restored cluster is silently ignored.
## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/RedshiftClusterCfnProvisioner.java[142-159]
- src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[352-361]
## Recommended Fix
Compare the requested key with the existing cluster's managed-secret key on updates. Update the secret encryption and persisted cluster metadata through the Secrets Manager-backed service path, without restoring the snapshot again; cover a key-only stack update.

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


6. A slow snapshot restore stalls all Redshift writes ✓ Resolved
Description
The new restoreFromClusterSnapshot overload runs restoreSnapshot (container start, proxy setup
and SQL dump replay), then the password change and the Secrets Manager secret creation, all inside
mutate, which holds the singleton RedshiftService monitor. A large dump restored by a
CloudFormation stack therefore blocks every synchronized mutation, including createTags and
cluster create/modify/delete for unrelated clusters and accounts, until the restore finishes.
Code

src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[R1212-1214]

+        return withResourceLock("cluster", clusterIdentifier, () -> withResourceLock("snapshot", snapshotIdentifier,
+                () -> mutate(() -> {
+                    Cluster cluster = restoreSnapshot(clusterIdentifier, snapshotIdentifier, nodeType);
Relevance

●●● Strong

Recent snapshot-restore precedents accept fixes for replay failures and blocking snapshot I/O.

PR-#6346
PR-#5184

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
mutate is synchronized on the service. The new overload wraps the entire restore in it,
including containerManager.restoreSnapshot (dump replay) and secret creation. This contradicts the
stated design that snapshot I/O never takes the monitor. The same issue was fixed for snapshot dumps
in PR #6346.

src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[120-127]
src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1279-1295]
PR-#6346

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 new CloudFormation restore overload does container start, dump replay and secret creation while holding the global `synchronized` monitor through `mutate`. This blocks every other Redshift mutation.

## Fix Focus Areas
- src/main/java/io/github/hectorvent/floci/services/redshift/RedshiftService.java[1206-1235]

## Recommended Fix
Keep the per-resource cluster and snapshot locks. Only take `mutate` for the short metadata commits (put/flush of the cluster record). Do the container start, `containerManager.restoreSnapshot`, password change and secret creation outside the monitor, as the createSnapshot/deleteCluster paths do after PR #6346.

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


Grey Divider

Context sources
✅ Compliance rules (platform): 12 rules
✅ Web pages:
  +2 more
✅ Cross-repo context — repo relationships
  Explored: repo: floci-io/floci-duck (sha: a90c4bd1) — View relationship
Review mode: Auto: 🧠 Deep: Multiple credential, restoration, rollback, tagging, and replacement paths create dense defect risk.

Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

- Reconcile ManageMasterPassword and KMS key on in-place cluster update
- Avoid overriding inherited snapshot passwords on unrelated template changes
- Reconcile tags by deleting removed tags on update
- Mint ARN for parameter group tags to prevent invalid parameter errors
- Scope mutate locking during snapshot restore to prevent stalling writes
@pgermosen pgermosen added cloudformation AWS CloudFormation enhancement New feature or request redshift Amazon Redshift labels Oct 24, 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, not ready to merge yet. The SnapshotIdentifier restore belongs here, but the tag fix (Tags on a Redshift cluster or parameter group fail on main today), switching ManageMasterPassword and its KMS key in place, and dropping the service lock from the existing RestoreFromClusterSnapshot path each deserve their own PR.

The new private attributes, the password hash above all, should use __Floci keys like the other provisioners, since Fn::GetAtt only hides those. Floci::DBName can move with them.

The store write under mutate, the restored-cluster cleanup and the Secrets Manager check now repeat several times, so a small helper for each would keep them in one place.

@pgermosen pgermosen added the waiting-author Review posted; waiting on the PR author to respond label Oct 24, 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, the scope looks right now, but it's not quite ready yet. Values a replacement rollback has to put back already have a prefix, CfnRollback.USES_ATTR_PREFIX, which ReplacementCleanup restores by itself, as the Route53 health check does with its create-only values. Naming the Redshift keys with it lets the __FlociRedshiftPriorAttributes blob and the custom rollbackUpdate go away.

A stack created before this change still carries Floci::DBName, so falling back to it when the new key is missing keeps a DBName change on such a stack a replacement.

@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, the Redshift keys now go through the shared rollback, and falling back to Floci::DBName keeps a DBName change on older stacks a replacement.

(follow-up, separate PR) The pieces split out earlier still apply on main. A cluster or parameter group with Tags fails, because createTags gets the bare name and RedshiftService only accepts an ARN. A change to ManageMasterPassword or MasterPasswordSecretKmsKeyId on an existing cluster is ignored, since that path only calls modifyCluster. And the RestoreFromClusterSnapshot API still runs the whole restore under the service lock.

@pgermosen pgermosen removed the waiting-author Review posted; waiting on the PR author to respond label Oct 24, 2026
@pgermosen
pgermosen merged commit 4c70d6b into floci-io:main Oct 24, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cloudformation AWS CloudFormation enhancement New feature or request redshift Amazon Redshift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants