From dc6c331745d5010fd22cd2217abaaf147b72366e Mon Sep 17 00:00:00 2001 From: Brenden Hogan Date: Fri, 30 Oct 2026 03:47:24 +0000 Subject: [PATCH 1/2] fix(E3692): allow Multi-AZ read replicas and omitted StorageType E3692 treated ReplicationSourceIdentifier as a property that is not allowed on a Multi-AZ DB cluster and required AllocatedStorage, so every Multi-AZ read replica was flagged. RDS rejects AllocatedStorage on a Multi-AZ DB cluster read replica, because the replica uses the source's allocated storage. The rule also required StorageType, although RDS defaults it to io1 for Multi-AZ DB clusters. AllocatedStorage is now required only when ReplicationSourceIdentifier is absent and is not allowed when it is set, with a replica-specific message. StorageType is optional but still limited to io1, io2 and gp3. Fixes #4957 Fixes #4962 Signed-off-by: Brenden Hogan --- .../extensions/aws_rds_dbcluster/multiaz.json | 22 ++- .../rules/resources/rds/DbClusterMultiAz.py | 18 ++- .../resources/rds/test_db_cluster_multiaz.py | 144 +++++++++++++++++- 3 files changed, 170 insertions(+), 14 deletions(-) diff --git a/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json b/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json index c7af11b7ed..bb6791f071 100644 --- a/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json +++ b/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json @@ -14,6 +14,16 @@ ] }, "then": { + "else": { + "required": [ + "AllocatedStorage" + ] + }, + "if": { + "required": [ + "ReplicationSourceIdentifier" + ] + }, "properties": { "AvailabilityZones": false, "BacktrackWindow": false, @@ -25,7 +35,6 @@ "EngineMode": false, "GlobalClusterIdentifier": false, "NetworkType": false, - "ReplicationSourceIdentifier": false, "ScalingConfiguration": false, "ServerlessV2ScalingConfiguration": false, "SourceRegion": false, @@ -43,10 +52,13 @@ } }, "required": [ - "AllocatedStorage", "DBClusterInstanceClass", - "Iops", - "StorageType" - ] + "Iops" + ], + "then": { + "properties": { + "AllocatedStorage": false + } + } } } diff --git a/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py b/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py index 041522563c..1af7e7fa93 100644 --- a/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py +++ b/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py @@ -32,17 +32,21 @@ def __init__(self) -> None: all_matches=True, ) - # DBClusterInstanceClass is required - # AllocatedStorage is required - # Iops is required + # Rewrite messages for forbidden properties; read replicas get their own 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: - err.message = ( - "Additional properties are not allowed " - f"{err.path[0]!r} when creating Multi-AZ cluster" - ) + if list(err.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 diff --git a/test/unit/rules/resources/rds/test_db_cluster_multiaz.py b/test/unit/rules/resources/rds/test_db_cluster_multiaz.py index e5d640e4ec..e2c5844834 100644 --- a/test/unit/rules/resources/rds/test_db_cluster_multiaz.py +++ b/test/unit/rules/resources/rds/test_db_cluster_multiaz.py @@ -3,10 +3,12 @@ SPDX-License-Identifier: MIT-0 """ +import json from collections import deque import pytest +from cfnlint.api import lint from cfnlint.jsonschema import ValidationError from cfnlint.rules.resources.rds.DbClusterMultiAz import DbClusterMultiAz @@ -30,6 +32,15 @@ def rule(): }, [], ), + ( + { + "Engine": "postgres", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "Iops": 1000, + }, + [], + ), ( { "Engine": "aurora-mysql", @@ -78,7 +89,7 @@ def rule(): rule=DbClusterMultiAz(), path=deque([]), validator="required", - schema_path=deque(["then", "required"]), + schema_path=deque(["then", "else", "required"]), ), ValidationError( "'DBClusterInstanceClass' is a required property", @@ -94,8 +105,86 @@ def rule(): validator="required", schema_path=deque(["then", "required"]), ), + ], + ), + ( + { + "Engine": "postgres", + "DBClusterInstanceClass": "foo", + "Iops": 1000, + "StorageType": "io1", + "ReplicationSourceIdentifier": { + "Fn::GetAtt": ["SourceInstance", "DBInstanceArn"] + }, + }, + [], + ), + ( + { + "Engine": "postgres", + "DBClusterInstanceClass": "foo", + "Iops": 1000, + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [], + ), + ( + { + "Engine": "postgres", + "DBClusterInstanceClass": "foo", + "Iops": 1000, + "StorageType": "gp2", + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [ ValidationError( - "'StorageType' is a required property", + "'gp2' is not one of ['io1', 'io2', 'gp3']", + rule=DbClusterMultiAz(), + path=deque(["StorageType"]), + validator="enum", + schema_path=deque( + ["then", "properties", "StorageType", "then", "enum"] + ), + ), + ], + ), + ( + { + "Engine": "mysql", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "Iops": 1000, + "StorageType": "io1", + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [ + ValidationError( + "'AllocatedStorage' is not allowed on a Multi-AZ DB " + "cluster read replica (ReplicationSourceIdentifier is set)", + rule=DbClusterMultiAz(), + path=deque(["AllocatedStorage"]), + validator=None, + schema_path=deque( + ["then", "then", "properties", "AllocatedStorage"] + ), + ), + ], + ), + ( + { + "Engine": "mysql", + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [ + ValidationError( + "'DBClusterInstanceClass' is a required property", + rule=DbClusterMultiAz(), + path=deque([]), + validator="required", + schema_path=deque(["then", "required"]), + ), + ValidationError( + "'Iops' is a required property", rule=DbClusterMultiAz(), path=deque([]), validator="required", @@ -128,3 +217,54 @@ def rule(): def test_validate(instance, expected, rule, validator): errs = list(rule.validate(validator, "", instance, {})) assert errs == expected, f"Expected {expected} got {errs}" + + +@pytest.mark.parametrize( + "name,allocated_storage,expected", + [ + ( + "AllocatedStorage only on the primary branch", + {"Fn::If": ["IsReplica", {"Ref": "AWS::NoValue"}, 100]}, + [], + ), + ( + "AllocatedStorage on both branches", + 100, + [ + "'AllocatedStorage' is not allowed on a Multi-AZ DB " + "cluster read replica (ReplicationSourceIdentifier is set)" + ], + ), + ], +) +def test_conditional_read_replica(name, allocated_storage, expected): + template = { + "Parameters": {"SourceDbArn": {"Type": "String", "Default": ""}}, + "Conditions": { + "IsReplica": {"Fn::Not": [{"Fn::Equals": [{"Ref": "SourceDbArn"}, ""]}]} + }, + "Resources": { + "Cluster": { + "Type": "AWS::RDS::DBCluster", + "Properties": { + "Engine": "postgres", + "DBClusterInstanceClass": "db.m6gd.large", + "Iops": 1000, + "StorageType": "io1", + "AllocatedStorage": allocated_storage, + "ReplicationSourceIdentifier": { + "Fn::If": [ + "IsReplica", + {"Ref": "SourceDbArn"}, + {"Ref": "AWS::NoValue"}, + ] + }, + }, + } + }, + } + matches = lint(json.dumps(template), regions=["us-east-1"]) + + assert [ + match.message for match in matches if match.rule.id == "E3692" + ] == expected, f"Test {name!r} failed with {matches!r}" From 5ce4b0253072b4e0be754d0c1777525ed08789f8 Mon Sep 17 00:00:00 2001 From: Brenden Hogan Date: Wed, 4 Nov 2026 02:31:28 +0000 Subject: [PATCH 2/2] fix(E3692): require Iops only for io1, io2 or no StorageType A Multi-AZ DB cluster with StorageType gp3 needs no Iops; RDS sets a baseline of 3000 IOPS. Iops is now required only when StorageType is io1 or io2, or when StorageType is omitted. With neither StorageType nor Iops, RDS uses gp2, which Multi-AZ DB clusters do not support, so that case gets its own message. The same rules apply to read replicas. Signed-off-by: Brenden Hogan --- .../extensions/aws_rds_dbcluster/multiaz.json | 39 +++++- .../rules/resources/rds/DbClusterMultiAz.py | 22 +++- .../resources/rds/test_db_cluster_multiaz.py | 113 +++++++++++++++++- 3 files changed, 165 insertions(+), 9 deletions(-) diff --git a/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json b/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json index bb6791f071..4dd6308c9c 100644 --- a/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json +++ b/src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/multiaz.json @@ -14,6 +14,42 @@ ] }, "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" @@ -52,8 +88,7 @@ } }, "required": [ - "DBClusterInstanceClass", - "Iops" + "DBClusterInstanceClass" ], "then": { "properties": { diff --git a/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py b/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py index 1af7e7fa93..b6f47bc66f 100644 --- a/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py +++ b/src/cfnlint/rules/resources/rds/DbClusterMultiAz.py @@ -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" @@ -32,13 +36,25 @@ def __init__(self) -> None: all_matches=True, ) - # Rewrite messages for forbidden properties; read replicas get their own + # 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: - if list(err.schema_path)[:2] == ["then", "then"]: + 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 = ( + "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)" diff --git a/test/unit/rules/resources/rds/test_db_cluster_multiaz.py b/test/unit/rules/resources/rds/test_db_cluster_multiaz.py index e2c5844834..edb1d711e6 100644 --- a/test/unit/rules/resources/rds/test_db_cluster_multiaz.py +++ b/test/unit/rules/resources/rds/test_db_cluster_multiaz.py @@ -99,11 +99,13 @@ def rule(): schema_path=deque(["then", "required"]), ), ValidationError( - "'Iops' is a required property", + "Set 'Iops' or set 'StorageType' to 'gp3'; without either, " + "RDS uses gp2 storage, which Multi-AZ DB clusters do not " + "support", rule=DbClusterMultiAz(), path=deque([]), validator="required", - schema_path=deque(["then", "required"]), + schema_path=deque(["then", "allOf", 1, "then", "required"]), ), ], ), @@ -184,11 +186,91 @@ def rule(): schema_path=deque(["then", "required"]), ), ValidationError( - "'Iops' is a required property", + "Set 'Iops' or set 'StorageType' to 'gp3'; without either, " + "RDS uses gp2 storage, which Multi-AZ DB clusters do not " + "support", rule=DbClusterMultiAz(), path=deque([]), validator="required", - schema_path=deque(["then", "required"]), + schema_path=deque(["then", "allOf", 1, "then", "required"]), + ), + ], + ), + ( + { + "Engine": "postgres", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "StorageType": "gp3", + }, + [], + ), + ( + { + "Engine": "postgres", + "DBClusterInstanceClass": "foo", + "StorageType": "gp3", + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [], + ), + ( + { + "Engine": "postgres", + "DBClusterInstanceClass": "foo", + "StorageType": "io1", + "ReplicationSourceIdentifier": {"Ref": "SourceDbArn"}, + }, + [ + ValidationError( + "'Iops' is a required property when 'StorageType' is 'io1'", + rule=DbClusterMultiAz(), + path=deque([]), + validator="required", + schema_path=deque(["then", "allOf", 0, "then", "required"]), + ), + ], + ), + ( + { + "Engine": "postgres", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "StorageType": {"Ref": "StorageType"}, + }, + [], + ), + ( + { + "Engine": "postgres", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "StorageType": "io2", + }, + [ + ValidationError( + "'Iops' is a required property when 'StorageType' is 'io2'", + rule=DbClusterMultiAz(), + path=deque([]), + validator="required", + schema_path=deque(["then", "allOf", 0, "then", "required"]), + ), + ], + ), + ( + { + "Engine": "mysql", + "AllocatedStorage": 100, + "DBClusterInstanceClass": "foo", + "StorageType": "io1", + }, + [ + ValidationError( + "'Iops' is a required property when 'StorageType' is 'io1'", + rule=DbClusterMultiAz(), + path=deque([]), + validator="required", + schema_path=deque(["then", "allOf", 0, "then", "required"]), ), ], ), @@ -268,3 +350,26 @@ def test_conditional_read_replica(name, allocated_storage, expected): assert [ match.message for match in matches if match.rule.id == "E3692" ] == expected, f"Test {name!r} failed with {matches!r}" + + +def test_conditional_storage_type(): + template = { + "Parameters": {"UseIo1": {"Type": "String", "Default": "false"}}, + "Conditions": {"IsIo1": {"Fn::Equals": [{"Ref": "UseIo1"}, "true"]}}, + "Resources": { + "Cluster": { + "Type": "AWS::RDS::DBCluster", + "Properties": { + "Engine": "postgres", + "DBClusterInstanceClass": "db.m6gd.large", + "AllocatedStorage": 100, + "StorageType": {"Fn::If": ["IsIo1", "io1", "gp3"]}, + }, + } + }, + } + matches = lint(json.dumps(template), regions=["us-east-1"]) + + assert [match.message for match in matches if match.rule.id == "E3692"] == [ + "'Iops' is a required property when 'StorageType' is 'io1'" + ], f"Got {matches!r}"