Skip to content

Commit

Permalink
Fixed bug in new Config recorder logic (#6434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikegrima authored Jun 23, 2023
1 parent 9a247d5 commit 10106d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
10 changes: 8 additions & 2 deletions moto/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,10 @@ def put_configuration_recorder(self, config_recorder: Dict[str, Any]) -> None:
if rgroup.get("allSupported", False):
if (
rgroup.get("resourceTypes", [])
or rgroup.get("exclusionByResourceTypes", {})
or (
rgroup.get("exclusionByResourceTypes", {"resourceTypes": []})
!= {"resourceTypes": []}
)
or recording_strategy not in {None, "ALL_SUPPORTED_RESOURCE_TYPES"}
):
raise InvalidRecordingGroupException()
Expand All @@ -1245,7 +1248,10 @@ def put_configuration_recorder(self, config_recorder: Dict[str, Any]) -> None:
elif rgroup.get("resourceTypes", []):
if (
rgroup.get("includeGlobalResourceTypes", False)
or rgroup.get("exclusionByResourceTypes", {})
or (
rgroup.get("exclusionByResourceTypes", {"resourceTypes": []})
!= {"resourceTypes": []}
)
or recording_strategy not in {None, "INCLUSION_BY_RESOURCE_TYPES"}
):
raise InvalidRecordingGroupException()
Expand Down
23 changes: 23 additions & 0 deletions tests/test_config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def test_put_configuration_recorder():
"exclusionByResourceTypes": {"resourceTypes": []},
"recordingStrategy": {"useOnly": "EXCLUSION_BY_RESOURCE_TYPES"},
},
{
"resourceTypes": ["AWS::S3::Bucket"],
"exclusionByResourceTypes": {"resourceTypes": ["AWS::S3::Bucket"]},
},
{"includeGlobalResourceTypes": False, "resourceTypes": []},
{"includeGlobalResourceTypes": True},
{"resourceTypes": []},
Expand Down Expand Up @@ -199,6 +203,7 @@ def test_put_configuration_recorder():
"allSupported": False,
"includeGlobalResourceTypes": False,
"resourceTypes": ["AWS::EC2::Volume", "AWS::EC2::VPC"],
"exclusionByResourceTypes": {"resourceTypes": []},
},
}
)
Expand Down Expand Up @@ -256,6 +261,24 @@ def test_put_configuration_recorder():
"recordingGroup"
]["allSupported"]

# Try this again, but this time, supply all the excess fields as empty:
client.put_configuration_recorder(
ConfigurationRecorder={
"name": "testrecorder",
"roleARN": "somearn",
"recordingGroup": {
"allSupported": True,
"includeGlobalResourceTypes": True,
"resourceTypes": [],
"exclusionByResourceTypes": {"resourceTypes": []},
"recordingStrategy": {"useOnly": "ALL_SUPPORTED_RESOURCE_TYPES"},
},
}
)
assert client.describe_configuration_recorders()["ConfigurationRecorders"][0][
"recordingGroup"
]["allSupported"]

# Update again for exclusions:
client.put_configuration_recorder(
ConfigurationRecorder={
Expand Down

0 comments on commit 10106d7

Please sign in to comment.