Skip to content

Commit d1555d7

Browse files
authored
Merge pull request #19 from gokendra1/includeGlobalResourceBugfix
Include global resource bugfix
2 parents d08e994 + fc4e1a0 commit d1555d7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ct_configrecorder_override_consumer.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
8989
CONFIG_RECORDER_DAILY_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_OVERRIDE_DAILY_RESOURCE_LIST')
9090
CONFIG_RECORDER_OVERRIDE_DAILY_RESOURCE_LIST = CONFIG_RECORDER_DAILY_RESOURCE_STRING.split(
9191
',') if CONFIG_RECORDER_DAILY_RESOURCE_STRING != '' else []
92+
93+
CONFIG_RECORDER_DAILY_GLOBAL_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_OVERRIDE_DAILY_GLOBAL_RESOURCE_LIST')
94+
CONFIG_RECORDER_DAILY_GLOBAL_RESOURCE_LIST = CONFIG_RECORDER_DAILY_GLOBAL_RESOURCE_STRING.split(
95+
',') if CONFIG_RECORDER_DAILY_GLOBAL_RESOURCE_STRING != '' else []
96+
97+
9298
CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING = os.getenv('CONFIG_RECORDER_OVERRIDE_EXCLUDED_RESOURCE_LIST')
9399
CONFIG_RECORDER_EXCLUSION_RESOURCE_LIST = CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING.split(
94100
',') if CONFIG_RECORDER_EXCLUSION_RESOURCE_STRING != '' else []
@@ -99,14 +105,18 @@ def assume_role(account_id, role='AWSControlTowerExecution'):
99105
CONFIG_RECORDER_OVERRIDE_DAILY_RESOURCE_LIST[:] = res
100106

101107
# Event = Delete is when stack is deleted, we rollback changed made and leave it as ControlTower Intended
108+
home_region = os.getenv('CONTROL_TOWER_HOME_REGION') == aws_region
109+
if home_region:
110+
CONFIG_RECORDER_OVERRIDE_DAILY_RESOURCE_LIST += CONFIG_RECORDER_DAILY_GLOBAL_RESOURCE_LIST
111+
102112
if event == 'Delete':
103113
response = configservice.put_configuration_recorder(
104114
ConfigurationRecorder={
105115
'name': 'aws-controltower-BaselineConfigRecorder',
106116
'roleARN': role_arn,
107117
'recordingGroup': {
108118
'allSupported': True,
109-
'includeGlobalResourceTypes': False
119+
'includeGlobalResourceTypes': home_region
110120
}
111121
})
112122
logging.info(f'Response for put_configuration_recorder :{response} ')

template.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Parameters:
1919
Default: "AWS::AutoScaling::AutoScalingGroup,AWS::AutoScaling::LaunchConfiguration"
2020
Type: String
2121

22+
ConfigRecorderDailyGlobalResourceTypes:
23+
Description: List of Global resource types to be set to a daily cadence in the AWS Control Tower home region
24+
Default: "AWS::IAM::Policy,AWS::IAM::User,AWS::IAM::Role,AWS::IAM::Group"
25+
Type: String
26+
2227
ConfigRecorderDefaultRecordingFrequency:
2328
Description: Default Frequency of recording configuration changes.
2429
Default: CONTINUOUS
@@ -109,8 +114,10 @@ Resources:
109114
Variables:
110115
LOG_LEVEL: INFO
111116
CONFIG_RECORDER_OVERRIDE_DAILY_RESOURCE_LIST: !Ref ConfigRecorderDailyResourceTypes
117+
CONFIG_RECORDER_OVERRIDE_DAILY_GLOBAL_RESOURCE_LIST: !Ref ConfigRecorderDailyGlobalResourceTypes
112118
CONFIG_RECORDER_OVERRIDE_EXCLUDED_RESOURCE_LIST: !Ref ConfigRecorderExcludedResourceTypes
113119
CONFIG_RECORDER_DEFAULT_RECORDING_FREQUENCY: !Ref ConfigRecorderDefaultRecordingFrequency
120+
CONTROL_TOWER_HOME_REGION: !Ref 'AWS::Region'
114121

115122
ConsumerLambdaEventSourceMapping:
116123
Type: AWS::Lambda::EventSourceMapping

0 commit comments

Comments
 (0)