Skip to content

Commit 5c4f1b1

Browse files
authored
Read replicas don't need backup period (#3171)
1 parent b3cec6a commit 5c4f1b1

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

Diff for: src/cfnlint/rules/resources/RetentionPeriodOnResourceTypesWithAutoExpiringContent.py

+23-10
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ def match(self, cfn):
6666
{
6767
"Attribute": "BackupRetentionPeriod",
6868
"SourceUrl": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-backupretentionperiod",
69-
"CheckAttribute": "Engine",
70-
"CheckAttributeRegex": re.compile("^((?!aurora).)*$"),
69+
"Checks": [
70+
{
71+
"CheckAttribute": "Engine",
72+
"CheckAttributeRegex": re.compile("aurora.*"),
73+
},
74+
{
75+
"CheckAttributeNotSet": "SourceDBInstanceIdentifier",
76+
},
77+
],
7178
}
7279
],
7380
"AWS::RDS::DBCluster": [
@@ -94,14 +101,20 @@ def match(self, cfn):
94101
value = property_set.get(attr_def.get("Attribute"))
95102
if not value:
96103
message = f'The default retention period will delete the data after a pre-defined time. Set an explicit values to avoid data loss on resource : {"/".join(str(x) for x in error_path)}'
97-
if attr_def.get("CheckAttribute"):
98-
if self._validate_property(
99-
property_set.get(
100-
attr_def.get("CheckAttribute")
101-
),
102-
attr_def.get("CheckAttributeRegex"),
103-
):
104-
matches.append(RuleMatch(error_path, message))
104+
for check in attr_def.get("Checks", []):
105+
if "CheckAttribute" in check:
106+
if self._validate_property(
107+
property_set.get(
108+
check.get("CheckAttribute")
109+
),
110+
check.get("CheckAttributeRegex"),
111+
):
112+
break
113+
if "CheckAttributeNotSet" in check:
114+
if property_set.get(
115+
check.get("CheckAttributeNotSet")
116+
):
117+
break
105118
else:
106119
matches.append(RuleMatch(error_path, message))
107120
if isinstance(value, dict):

Diff for: test/fixtures/templates/good/resources/rds/retention_period.yaml

+20
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,24 @@ Resources:
1818
PerformanceInsightsKMSKeyId: !Ref KmsKey
1919
PerformanceInsightsRetentionPeriod: 7
2020
PubliclyAccessible: false
21+
ReadReplica:
22+
Type: AWS::RDS::DBInstance
23+
DeletionPolicy: Retain
24+
UpdateReplacePolicy: Retain
25+
Properties:
26+
AllowMajorVersionUpgrade: false
27+
AutoMinorVersionUpgrade: !Ref AutoMinorVersionUpgrade
28+
DBClusterIdentifier: !Ref AuroraCluster
29+
DBInstanceClass: !Ref InstanceClass
30+
DBInstanceIdentifier: "MyAuroraInstance"
31+
DBParameterGroupName: !Ref ParamGroup
32+
DBSubnetGroupName: !Ref SubnetGroup
33+
DeleteAutomatedBackups: !Ref DeleteAutomatedBackups
34+
EnablePerformanceInsights: !Ref EnablePerformanceInsights
35+
Engine: mysql
36+
SourceDBInstanceIdentifier: SourceDb # marks a read replica and doesn't need backups
37+
EngineVersion: !Ref EngineVersion
38+
PerformanceInsightsKMSKeyId: !Ref KmsKey
39+
PerformanceInsightsRetentionPeriod: 7
40+
PubliclyAccessible: false
2141

0 commit comments

Comments
 (0)