Skip to content
Merged
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
12 changes: 9 additions & 3 deletions ct_configrecorder_override_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def assume_role(account_id, role='AWSControlTowerExecution'):

# Describe configuration recorder
configrecorder = configservice.describe_configuration_recorders()
logging.info(f'Existing Configuration Recorder :', configrecorder)
logging.info(f'Existing Configuration Recorder: {configrecorder}')

# Get the name of the existing recorder if it exists, otherwise use the default name
recorder_name = 'aws-controltower-BaselineConfigRecorder'
if configrecorder and 'ConfigurationRecorders' in configrecorder and len(configrecorder['ConfigurationRecorders']) > 0:
recorder_name = configrecorder['ConfigurationRecorders'][0]['name']
logging.info(f'Using existing recorder name: {recorder_name}')

# ControlTower created configuration recorder with name "aws-controltower-BaselineConfigRecorder" and we will update just that
try:
Expand All @@ -102,7 +108,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
if event == 'Delete':
response = configservice.put_configuration_recorder(
ConfigurationRecorder={
'name': 'aws-controltower-BaselineConfigRecorder',
'name': recorder_name,
'roleARN': role_arn,
'recordingGroup': {
'allSupported': True,
Expand All @@ -113,7 +119,7 @@ def assume_role(account_id, role='AWSControlTowerExecution'):

else:
config_recorder = {
'name': 'aws-controltower-BaselineConfigRecorder',
'name': recorder_name,
'roleARN': role_arn,
'recordingGroup': {
'allSupported': False,
Expand Down