Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RDS Validations #2171

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions troposphere/validators/rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def validate_dbinstance(self) -> None:
)

nonetype = type(None)
dbclusteridentifier = self.properties.get("DBClusterIdentifier", None)
allocated_storage = self.properties.get("AllocatedStorage")
avail_zone = self.properties.get("AvailabilityZone", None)
multi_az = self.properties.get("MultiAZ", None)
Expand All @@ -382,11 +383,20 @@ def validate_dbinstance(self) -> None:
)

storage_type = self.properties.get("StorageType", None)
if storage_type and storage_type in ["io1"] and "Iops" not in self.properties:
if (
not dbclusteridentifier
and storage_type
and storage_type in ["io1"]
and "Iops" not in self.properties
):
raise ValueError("Must specify Iops if using StorageType io1")

if (
storage_type
not dbclusteridentifier
and storage_type
and not isinstance(storage_type, (AWSHelperFn, nonetype))
and engine
and not isinstance(engine, (AWSHelperFn, nonetype))
and engine in ["mariadb", "mysql", "postgres"]
and storage_type in ["gp3"]
and int(allocated_storage) < 400
Expand All @@ -397,7 +407,11 @@ def validate_dbinstance(self) -> None:
)

if (
storage_type
not dbclusteridentifier
and storage_type
and not isinstance(storage_type, (AWSHelperFn, nonetype))
and engine
and not isinstance(engine, (AWSHelperFn, nonetype))
and "oracle" in engine
and storage_type in ["gp3"]
and int(allocated_storage) < 200
Expand All @@ -408,7 +422,12 @@ def validate_dbinstance(self) -> None:
)

iops = self.properties.get("Iops", None)
if iops and not isinstance(iops, AWSHelperFn) and storage_type not in ["gp3"]:
if (
not dbclusteridentifier
and iops
and not isinstance(iops, AWSHelperFn)
and storage_type not in ["gp3"]
):
min_storage_size = 100
if not isinstance(engine, AWSHelperFn) and engine.startswith("sqlserver"):
min_storage_size = 20
Expand All @@ -429,7 +448,12 @@ def validate_dbinstance(self) -> None:
raise ValueError(
"AllocatedStorage must be no less than " "1/50th the provisioned Iops"
)
if iops and not isinstance(iops, AWSHelperFn) and storage_type in ["gp3"]:
if (
not dbclusteridentifier
and iops
and not isinstance(iops, AWSHelperFn)
and storage_type in ["gp3"]
):
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html#gp3-storage
min_iops_to_allocated_storage_ratio = 0.0
max_iops_to_allocated_storage_ratio = 500.0
Expand Down