From 72df295d7abea463cea214c7a9d6cbb27bc504da Mon Sep 17 00:00:00 2001 From: Harshil Sanjay Jain Date: Wed, 23 Oct 2024 13:38:10 -0400 Subject: [PATCH] Add final-db-snapshot-identifier validation --- .../java/gyro/aws/rds/DbClusterResource.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/gyro/aws/rds/DbClusterResource.java b/src/main/java/gyro/aws/rds/DbClusterResource.java index 7f5367acd..a533b7db2 100644 --- a/src/main/java/gyro/aws/rds/DbClusterResource.java +++ b/src/main/java/gyro/aws/rds/DbClusterResource.java @@ -41,6 +41,7 @@ import gyro.core.validation.ConflictsWith; import gyro.core.validation.Required; import gyro.core.validation.ValidStrings; +import gyro.core.validation.ValidationError; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.CreateDbClusterRequest; import software.amazon.awssdk.services.rds.model.CreateDbClusterResponse; @@ -1094,7 +1095,8 @@ public void delete(GyroUI ui, State state) { client.deleteDBCluster( r -> r.dbClusterIdentifier(getIdentifier()) - .finalDBSnapshotIdentifier(!getSkipFinalSnapshot() ? getFinalDbSnapshotIdentifier() : null) + .finalDBSnapshotIdentifier( + Boolean.TRUE.equals(getSkipFinalSnapshot()) ? null : getFinalDbSnapshotIdentifier()) .skipFinalSnapshot(getSkipFinalSnapshot()) ); @@ -1129,4 +1131,20 @@ private void waitForActiveStatus(RdsClient client, TimeoutSettings.Action action throw new GyroException("Unable to reach 'available' state for rds db cluster - " + getIdentifier()); } } + + @Override + public List validate(Set configuredFields) { + ArrayList errors = new ArrayList<>(); + + if ((getSkipFinalSnapshot() == null || Boolean.FALSE.equals(getSkipFinalSnapshot())) && + getFinalDbSnapshotIdentifier() == null) { + errors.add(new ValidationError( + this, + "final-db-snapshot-identifier", + "'final-db-snapshot-identifier' is required when 'skip-final-snapshot' is unspecified or set to 'false'." + )); + } + + return errors; + } }