Skip to content

Commit

Permalink
Add final-db-snapshot-identifier validation
Browse files Browse the repository at this point in the history
  • Loading branch information
harjain99 committed Oct 23, 2024
1 parent 0bd2a76 commit 72df295
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/gyro/aws/rds/DbClusterResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
);

Expand Down Expand Up @@ -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<ValidationError> validate(Set<String> configuredFields) {
ArrayList<ValidationError> 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;
}
}

0 comments on commit 72df295

Please sign in to comment.