Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 53 additions & 6 deletions src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,52 @@
]
},
"then": {
"allOf": [
{
"if": {
"properties": {
"StorageType": {
"enum": [
"io1",
"io2"
]
}
},
"required": [
"StorageType"
],
"type": "object"
},
"then": {
"required": [
"Iops"
]
}
},
{
"if": {
"properties": {
"StorageType": false
},
"type": "object"
},
"then": {
"required": [
"Iops"
]
}
}
],
"else": {
"required": [
"AllocatedStorage"
]
},
"if": {
"required": [
"ReplicationSourceIdentifier"
]
},
"properties": {
"AvailabilityZones": false,
"BacktrackWindow": false,
Expand All @@ -25,7 +71,6 @@
"EngineMode": false,
"GlobalClusterIdentifier": false,
"NetworkType": false,
"ReplicationSourceIdentifier": false,
"ScalingConfiguration": false,
"ServerlessV2ScalingConfiguration": false,
"SourceRegion": false,
Expand All @@ -43,10 +88,12 @@
}
},
"required": [
"AllocatedStorage",
"DBClusterInstanceClass",
"Iops",
"StorageType"
]
"DBClusterInstanceClass"
],
"then": {
"properties": {
"AllocatedStorage": false
}
}
}
}
32 changes: 26 additions & 6 deletions src/cfnlint/rules/resources/rds/DbClusterMultiAz.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
from cfnlint.jsonschema import ValidationResult, Validator
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails

# Schema paths of the two Iops requirements in multiaz.json "then.allOf"
_IOPS_FOR_PROVISIONED_STORAGE = ["then", "allOf", 0, "then", "required"]
_IOPS_FOR_NO_STORAGE_TYPE = ["then", "allOf", 1, "then", "required"]


class DbClusterMultiAz(CfnLintJsonSchema):
id = "E3692"
Expand All @@ -32,17 +36,33 @@ def __init__(self) -> None:
all_matches=True,
)

# DBClusterInstanceClass is required
# AllocatedStorage is required
# Iops is required
# Rewrite messages for forbidden properties and for conditional Iops
def validate(
self, validator: Validator, keywords: Any, instance: Any, schema: dict[str, Any]
) -> ValidationResult:
for err in super().validate(validator, keywords, instance, schema):
if err.schema is False:
schema_path = list(err.schema_path)
if schema_path == _IOPS_FOR_PROVISIONED_STORAGE:
err.message = (
"'Iops' is a required property when 'StorageType' is "
f"{err.instance.get('StorageType')!r}"
)
elif schema_path == _IOPS_FOR_NO_STORAGE_TYPE:
err.message = (
"Additional properties are not allowed "
f"{err.path[0]!r} when creating Multi-AZ cluster"
"Set 'Iops' or set 'StorageType' to 'gp3'; without either, "
"RDS uses gp2 storage, which Multi-AZ DB clusters do not "
"support"
)
elif err.schema is False:
if schema_path[:2] == ["then", "then"]:
err.message = (
f"{err.path[0]!r} is not allowed on a Multi-AZ DB "
"cluster read replica (ReplicationSourceIdentifier is set)"
)
else:
err.message = (
"Additional properties are not allowed "
f"{err.path[0]!r} when creating Multi-AZ cluster"
)

yield err
Loading
Loading