Skip to content

Commit

Permalink
Add validator for AWS::RDS::DBCluster.ServerlessV2ScalingConfiguration (
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry153fish authored Mar 23, 2023
1 parent 73fbfaf commit 725e41c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
13 changes: 13 additions & 0 deletions tests/test_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,16 @@ def test_validate_capacity(self):

with self.assertRaises(ValueError):
vrds.validate_capacity(100001)

def test_v2_validate_capacity(self):
vrds.validate_v2_capacity(64)
vrds.validate_v2_capacity(0.5)

with self.assertRaises(ValueError):
vrds.validate_v2_capacity(129)

with self.assertRaises(ValueError):
vrds.validate_v2_capacity(1.1)

with self.assertRaises(ValueError):
vrds.validate_v2_max_capacity(0.5)
8 changes: 5 additions & 3 deletions troposphere/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


from . import AWSObject, AWSProperty, PropsDictType, Tags
from .validators import boolean, double, integer
from .validators import boolean, integer
from .validators.rds import (
validate_backtrack_window,
validate_backup_retention_period,
Expand All @@ -21,6 +21,8 @@
validate_network_port,
validate_str_or_int,
validate_tags_or_list,
validate_v2_capacity,
validate_v2_max_capacity,
)


Expand Down Expand Up @@ -67,8 +69,8 @@ class ServerlessV2ScalingConfiguration(AWSProperty):
"""

props: PropsDictType = {
"MaxCapacity": (double, False),
"MinCapacity": (double, False),
"MaxCapacity": (validate_v2_max_capacity, False),
"MinCapacity": (validate_v2_capacity, False),
}


Expand Down
43 changes: 43 additions & 0 deletions troposphere/validators/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,49 @@ def validate_capacity(capacity):
return capacity


def validate_v2_capacity(capacity):
"""
Validate ServerlessV2ScalingConfiguration capacity for serverless DBCluster
Property: ServerlessV2ScalingConfiguration.MinCapacity
"""
if capacity < 0.5:
raise ValueError(
"ServerlessV2ScalingConfiguration capacity {} cannot be smaller than 0.5.".format(
capacity
)
)
if capacity > 128:
raise ValueError(
"ServerlessV2ScalingConfiguration capacity {} cannot be larger than 128.".format(
capacity
)
)

if capacity * 10 % 5 != 0:
raise ValueError(
"ServerlessV2ScalingConfiguration capacity {} cannot be only specific in half-step increments.".format(
capacity
)
)

return capacity


def validate_v2_max_capacity(capacity):
"""
Validate ServerlessV2ScalingConfiguration max capacity for serverless DBCluster
Property: ServerlessV2ScalingConfiguration.MaxCapacity
"""
if capacity < 1:
raise ValueError(
"ServerlessV2ScalingConfiguration max capacity {} cannot be smaller than 1.".format(
capacity
)
)

return validate_v2_capacity(capacity)


def validate_dbinstance(self) -> None:
"""
Class: DBInstance
Expand Down

0 comments on commit 725e41c

Please sign in to comment.