mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
feat(rds): IAM role associations for DB clusters and instances (#5367)
* feat(rds): IAM role associations for DB clusters and instances AddRoleToDBCluster, RemoveRoleFromDBCluster, AddRoleToDBInstance and RemoveRoleFromDBInstance answered UnsupportedOperation, and DBCluster and DBInstance carried no AssociatedRoles, so Terraform's aws_rds_cluster_role_association and aws_db_instance_role_association could not apply. Clusters and instances now keep their associated roles and report them as AssociatedRoles, ACTIVE as soon as they are added. The four actions raise the faults the API model lists, and CreateDBCluster accepts AssociatedRoles, checked before the cluster is created. Feature names are not yet validated against the engine. Closes #5343 * fix(rds): route the instance role actions, and refuse only a repeated cluster role AddRoleToDBInstance and RemoveRoleFromDBInstance were missing from RDS_ACTIONS, so a request with no credential scope reached SQS. DBClusterRoleAlreadyExists covers the role ARN only, so a cluster now takes a second role for a feature that already has one. Instances keep refusing a repeated role or feature, as their fault documents. CreateDBCluster reads every AssociatedRoles index, gaps included, and refuses an entry without a RoleArn. It associates the roles in one step and deletes the new cluster if that is refused. * refactor(rds): import the types parseAssociatedRoles uses The regex and sorted-set types were written with their packages inline; AGENTS.md asks for imports. The role association compat test gains a DisplayName like the others in its class. * docs(rds): count the role association actions alongside the catalogue reads #5196 and this branch each added four RDS actions, so the service matrix count is 98.
This commit is contained in:
1 parent
a017c94ecc
commit
5e48cbb80b
12 files changed
+731
-2
No files matched your search
+63
@@ -18,15 +18,22 @@ import software.amazon.awssdk.services.rds.model.CreateDbProxyResponse;
|
||||
import software.amazon.awssdk.services.rds.model.CreateDbSubnetGroupResponse;
|
||||
import software.amazon.awssdk.services.rds.model.CreateOptionGroupResponse;
|
||||
import software.amazon.awssdk.services.rds.model.DBCluster;
|
||||
import software.amazon.awssdk.services.rds.model.DBClusterAssociatedRole;
|
||||
import software.amazon.awssdk.services.rds.model.DBClusterEndpoint;
|
||||
import software.amazon.awssdk.services.rds.model.DBClusterRole;
|
||||
import software.amazon.awssdk.services.rds.model.DBClusterSnapshot;
|
||||
import software.amazon.awssdk.services.rds.model.DBEngineVersion;
|
||||
import software.amazon.awssdk.services.rds.model.DBInstance;
|
||||
import software.amazon.awssdk.services.rds.model.DBInstanceRole;
|
||||
import software.amazon.awssdk.services.rds.model.DBProxyTarget;
|
||||
import software.amazon.awssdk.services.rds.model.DBSnapshot;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterEndpointAlreadyExistsException;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterEndpointNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterRoleAlreadyExistsException;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterRoleNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DbClusterSnapshotNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DbInstanceRoleAlreadyExistsException;
|
||||
import software.amazon.awssdk.services.rds.model.DbInstanceRoleNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DbSnapshotAlreadyExistsException;
|
||||
import software.amazon.awssdk.services.rds.model.DbSnapshotNotFoundException;
|
||||
import software.amazon.awssdk.services.rds.model.DescribeDbProxiesResponse;
|
||||
@@ -757,6 +764,62 @@ class RdsControlPlaneTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("IAM role associations: add, describe and remove for a cluster and an instance")
|
||||
void sdkRoundTripsIamRoleAssociations() {
|
||||
String clusterName = TestFixtures.uniqueName("rds-roles-cluster");
|
||||
String instanceName = TestFixtures.uniqueName("rds-roles-db");
|
||||
String s3Role = "arn:aws:iam::000000000000:role/rds-s3-import";
|
||||
String lambdaRole = "arn:aws:iam::000000000000:role/rds-lambda";
|
||||
try {
|
||||
CreateDbClusterResponse created = rds.createDBCluster(b -> b
|
||||
.dbClusterIdentifier(clusterName)
|
||||
.engine("aurora-postgresql")
|
||||
.engineVersion("16.3")
|
||||
.masterUsername("admin")
|
||||
.masterUserPassword("roles-secret")
|
||||
.associatedRoles(DBClusterAssociatedRole.builder().roleArn(s3Role).featureName("s3Import").build()));
|
||||
assertThat(created.dbCluster().associatedRoles())
|
||||
.extracting(DBClusterRole::roleArn, DBClusterRole::featureName, DBClusterRole::status)
|
||||
.containsExactly(tuple(s3Role, "s3Import", "ACTIVE"));
|
||||
|
||||
rds.addRoleToDBCluster(b -> b.dbClusterIdentifier(clusterName).roleArn(lambdaRole));
|
||||
assertThat(rds.describeDBClusters(b -> b.dbClusterIdentifier(clusterName))
|
||||
.dbClusters().get(0).associatedRoles())
|
||||
.extracting(DBClusterRole::roleArn)
|
||||
.containsExactly(s3Role, lambdaRole);
|
||||
assertThatThrownBy(() -> rds.addRoleToDBCluster(b -> b.dbClusterIdentifier(clusterName).roleArn(s3Role)))
|
||||
.isInstanceOf(DbClusterRoleAlreadyExistsException.class);
|
||||
|
||||
rds.removeRoleFromDBCluster(b -> b.dbClusterIdentifier(clusterName).roleArn(s3Role));
|
||||
assertThatThrownBy(() -> rds.removeRoleFromDBCluster(b -> b
|
||||
.dbClusterIdentifier(clusterName).roleArn(s3Role)))
|
||||
.isInstanceOf(DbClusterRoleNotFoundException.class);
|
||||
|
||||
createDbInstance(rds, instanceName, "roles-secret");
|
||||
rds.addRoleToDBInstance(b -> b.dbInstanceIdentifier(instanceName).roleArn(s3Role).featureName("s3Import"));
|
||||
assertThat(rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
|
||||
.dbInstances().get(0).associatedRoles())
|
||||
.extracting(DBInstanceRole::roleArn, DBInstanceRole::featureName, DBInstanceRole::status)
|
||||
.containsExactly(tuple(s3Role, "s3Import", "ACTIVE"));
|
||||
assertThatThrownBy(() -> rds.addRoleToDBInstance(b -> b
|
||||
.dbInstanceIdentifier(instanceName).roleArn(lambdaRole).featureName("s3Import")))
|
||||
.isInstanceOf(DbInstanceRoleAlreadyExistsException.class);
|
||||
|
||||
rds.removeRoleFromDBInstance(b -> b.dbInstanceIdentifier(instanceName).roleArn(s3Role).featureName("s3Import"));
|
||||
assertThatThrownBy(() -> rds.removeRoleFromDBInstance(b -> b
|
||||
.dbInstanceIdentifier(instanceName).roleArn(s3Role).featureName("s3Import")))
|
||||
.isInstanceOf(DbInstanceRoleNotFoundException.class);
|
||||
} finally {
|
||||
deleteDbInstance(rds, instanceName);
|
||||
try {
|
||||
rds.deleteDBCluster(b -> b.dbClusterIdentifier(clusterName).skipFinalSnapshot(true));
|
||||
} catch (Exception e) {
|
||||
LOG.log(Level.WARNING, "Failed to clean up RDS cluster " + clusterName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Catalogue reads: engine versions, engine defaults and valid instance modifications")
|
||||
void sdkReadsTheEngineCatalogue() {
|
||||
|
||||
Reference in new issue
Block a user