From 35ab6cefe8940ac424c91857e825d54b730c7587 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Fri, 28 Jul 2023 14:34:35 +0000 Subject: [PATCH] RDS: create_db_cluster() now supports the VpcSecurityGroupIds-parameter (#6567) --- moto/rds/models.py | 4 ++-- moto/rds/responses.py | 3 +++ tests/test_rds/test_rds_clusters.py | 25 ++++++++----------------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/moto/rds/models.py b/moto/rds/models.py index 4743bc0b2..7ff975661 100644 --- a/moto/rds/models.py +++ b/moto/rds/models.py @@ -182,7 +182,7 @@ class Cluster: self.preferred_backup_window = "01:37-02:07" self.preferred_maintenance_window = "wed:02:40-wed:03:10" # This should default to the default security group - self.vpc_security_groups: List[str] = [] + self.vpc_security_group_ids: List[str] = kwargs["vpc_security_group_ids"] self.hosted_zone_id = "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(14) ) @@ -329,7 +329,7 @@ class Cluster: {% endfor %} - {% for id in cluster.vpc_security_groups %} + {% for id in cluster.vpc_security_group_ids %} {{ id }} active diff --git a/moto/rds/responses.py b/moto/rds/responses.py index cd80fef6a..4d2f33569 100644 --- a/moto/rds/responses.py +++ b/moto/rds/responses.py @@ -211,6 +211,9 @@ class RDSResponse(BaseResponse): "replication_source_identifier": self._get_param( "ReplicationSourceIdentifier" ), + "vpc_security_group_ids": self.unpack_list_params( + "VpcSecurityGroupIds", "VpcSecurityGroupId" + ), } def _get_export_task_kwargs(self) -> Dict[str, Any]: diff --git a/tests/test_rds/test_rds_clusters.py b/tests/test_rds/test_rds_clusters.py index 60aa83dc5..2b83979ef 100644 --- a/tests/test_rds/test_rds_clusters.py +++ b/tests/test_rds/test_rds_clusters.py @@ -193,29 +193,13 @@ def test_create_db_cluster__verify_default_properties(): ).should.be.greater_than_or_equal_to(cluster["ClusterCreateTime"]) -@mock_rds -def test_create_db_cluster_with_database_name(): - client = boto3.client("rds", region_name="eu-north-1") - - resp = client.create_db_cluster( - DBClusterIdentifier="cluster-id", - DatabaseName="users", - Engine="aurora", - MasterUsername="root", - MasterUserPassword="hunter2_", - ) - cluster = resp["DBCluster"] - cluster.should.have.key("DatabaseName").equal("users") - cluster.should.have.key("DBClusterIdentifier").equal("cluster-id") - cluster.should.have.key("DBClusterParameterGroup").equal("default.aurora8.0") - - @mock_rds def test_create_db_cluster_additional_parameters(): client = boto3.client("rds", region_name="eu-north-1") resp = client.create_db_cluster( AvailabilityZones=["eu-north-1b"], + DatabaseName="users", DBClusterIdentifier="cluster-id", Engine="aurora", EngineVersion="8.0.mysql_aurora.3.01.0", @@ -232,11 +216,13 @@ def test_create_db_cluster_additional_parameters(): "MinCapacity": 5, "AutoPause": True, }, + VpcSecurityGroupIds=["sg1", "sg2"], ) cluster = resp["DBCluster"] cluster.should.have.key("AvailabilityZones").equal(["eu-north-1b"]) + cluster.should.have.key("DatabaseName").equal("users") cluster.should.have.key("Engine").equal("aurora") cluster.should.have.key("EngineVersion").equal("8.0.mysql_aurora.3.01.0") cluster.should.have.key("EngineMode").equal("serverless") @@ -248,6 +234,11 @@ def test_create_db_cluster_additional_parameters(): assert cluster["DBSubnetGroup"] == "subnetgroupname" assert cluster["ScalingConfigurationInfo"] == {"MinCapacity": 5, "AutoPause": True} + security_groups = cluster["VpcSecurityGroups"] + assert len(security_groups) == 2 + assert {"VpcSecurityGroupId": "sg1", "Status": "active"} in security_groups + assert {"VpcSecurityGroupId": "sg2", "Status": "active"} in security_groups + @mock_rds def test_describe_db_cluster_after_creation():