Skip to content

Commit 39c5a1a

Browse files
authored
Add W3693 for aurora cluster properties (#3695)
* Add W3693 for aurora cluster properties * Update W3693 to only warn on aurora serverless v1
1 parent 8992c81 commit 39c5a1a

File tree

4 files changed

+142
-3
lines changed

4 files changed

+142
-3
lines changed

src/cfnlint/data/schemas/extensions/aws_rds_dbcluster/aurora.json

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
"Iops": false,
2121
"MonitoringInterval": false,
2222
"MonitoringRoleArn": false,
23-
"PerformanceInsightsEnabled": false,
24-
"PerformanceInsightsKmsKeyId": false,
25-
"PerformanceInsightsRetentionPeriod": false,
2623
"PubliclyAccessible": false,
2724
"StorageType": {
2825
"if": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"if": {
3+
"properties": {
4+
"Engine": {
5+
"enum": [
6+
"aurora-mysql",
7+
"aurora-postgresql"
8+
],
9+
"type": "string"
10+
},
11+
"EngineMode": {
12+
"enum": [
13+
"serverless"
14+
],
15+
"type": "string"
16+
}
17+
},
18+
"required": [
19+
"Engine",
20+
"EngineMode"
21+
]
22+
},
23+
"then": {
24+
"properties": {
25+
"PerformanceInsightsEnabled": false,
26+
"PerformanceInsightsKmsKeyId": false,
27+
"PerformanceInsightsRetentionPeriod": false
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
SPDX-License-Identifier: MIT-0
4+
"""
5+
6+
from __future__ import annotations
7+
8+
from typing import Any
9+
10+
import cfnlint.data.schemas.extensions.aws_rds_dbcluster
11+
from cfnlint.jsonschema import ValidationResult, Validator
12+
from cfnlint.rules.jsonschema.CfnLintJsonSchema import CfnLintJsonSchema, SchemaDetails
13+
14+
15+
class DbClusterAuroraWarning(CfnLintJsonSchema):
16+
id = "W3693"
17+
shortdesc = "Validate Aurora DB cluster configuration for ignored properties"
18+
description = (
19+
"When creating an Aurora DB Cluster there are fields that "
20+
"will allow for successful deployment but are ignored"
21+
)
22+
tags = ["resources"]
23+
source_url = "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#cfn-rds-dbcluster-engineversion"
24+
25+
def __init__(self) -> None:
26+
super().__init__(
27+
keywords=["Resources/AWS::RDS::DBCluster/Properties"],
28+
schema_details=SchemaDetails(
29+
module=cfnlint.data.schemas.extensions.aws_rds_dbcluster,
30+
filename="aurora_warning.json",
31+
),
32+
all_matches=True,
33+
)
34+
35+
def validate(
36+
self, validator: Validator, keywords: Any, instance: Any, schema: dict[str, Any]
37+
) -> ValidationResult:
38+
for err in super().validate(validator, keywords, instance, schema):
39+
if err.schema is False:
40+
err.message = (
41+
"Additional properties are not allowed "
42+
f"{err.path[0]!r} when creating Aurora cluster"
43+
)
44+
45+
yield err
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
SPDX-License-Identifier: MIT-0
4+
"""
5+
6+
from collections import deque
7+
8+
import pytest
9+
10+
from cfnlint.jsonschema import ValidationError
11+
from cfnlint.rules.resources.rds.DbClusterAuroraWarning import DbClusterAuroraWarning
12+
13+
14+
@pytest.fixture(scope="module")
15+
def rule():
16+
rule = DbClusterAuroraWarning()
17+
yield rule
18+
19+
20+
@pytest.mark.parametrize(
21+
"instance,expected",
22+
[
23+
(
24+
{"Engine": "aurora-mysql", "EngineMode": "serverless"},
25+
[],
26+
),
27+
(
28+
{
29+
"Engine": "aurora-mysql",
30+
"EngineMode": "provisioned",
31+
"PerformanceInsightsEnabled": True,
32+
},
33+
[],
34+
),
35+
(
36+
{
37+
"Engine": "aurora-mysql",
38+
"PerformanceInsightsEnabled": True,
39+
},
40+
[],
41+
),
42+
(
43+
{
44+
"Engine": "aurora-mysql",
45+
"EngineMode": "serverless",
46+
"PerformanceInsightsEnabled": True,
47+
},
48+
[
49+
ValidationError(
50+
(
51+
"Additional properties are not allowed "
52+
"'PerformanceInsightsEnabled' when creating Aurora cluster"
53+
),
54+
rule=DbClusterAuroraWarning(),
55+
path=deque(["PerformanceInsightsEnabled"]),
56+
validator=None,
57+
schema_path=deque(
58+
["then", "properties", "PerformanceInsightsEnabled"]
59+
),
60+
),
61+
],
62+
),
63+
],
64+
)
65+
def test_validate(instance, expected, rule, validator):
66+
errs = list(rule.validate(validator, "", instance, {}))
67+
assert errs == expected, f"Expected {expected} got {errs}"

0 commit comments

Comments
 (0)