diff --git a/src/main/java/gyro/aws/rds/DbClusterEndpointResource.java b/src/main/java/gyro/aws/rds/DbClusterEndpointResource.java index c9740e2f5..34a0866ae 100644 --- a/src/main/java/gyro/aws/rds/DbClusterEndpointResource.java +++ b/src/main/java/gyro/aws/rds/DbClusterEndpointResource.java @@ -29,6 +29,7 @@ import gyro.core.scope.State; 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.CreateDbClusterEndpointResponse; import software.amazon.awssdk.services.rds.model.DBClusterEndpoint; @@ -92,11 +93,11 @@ public void setDbCluster(DbClusterResource dbCluster) { } /** - * The type of the endpoint. + * The type of the endpoint. Cannot be set to ``WRITER`` if 'db-cluster' is set to ``Aurora``. */ @Required @Updatable - @ValidStrings({"READER", "ANY"}) + @ValidStrings({"READER", "WRITER", "ANY"}) public String getEndpointType() { return endpointType; } @@ -226,4 +227,25 @@ public void delete(GyroUI ui, State state) { r -> r.dbClusterEndpointIdentifier(getIdentifier()) ); } + + @Override + public List validate(Set configuredFields) { + List errors = new ArrayList<>(); + + // Add validation for Aurora DB and endpointType 'WRITER' + if (getDbCluster() != null) { + String engine = getDbCluster().getEngine(); + if (engine != null && getEndpointType() != null) { + if ((engine.equalsIgnoreCase("aurora-mysql") || engine.equalsIgnoreCase("aurora-postgresql")) + && getEndpointType().equalsIgnoreCase("WRITER")) { + errors.add(new ValidationError( + this, + "dbCluster", + "Database engine " + engine + " with endpointType 'WRITER' is not supported")); + } + } + } + + return errors; + } }