Skip to content

Commit

Permalink
Added compatibility for multiple deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
bajwkanw committed Nov 11, 2024
1 parent b905973 commit 2030ffe
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 43 deletions.
10 changes: 5 additions & 5 deletions src/DataCollectionModule/DataCollectionModule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"
HeidiDataCollectionDB:
Type: String
Description: Athena DataCollection DB name
Default: "heididatacollectiondb"
Default: "datacollectiondb"
EnableHealthModule:
Type: String
Description: Collects AWS Health data from different accounts
Expand All @@ -46,12 +46,12 @@ Outputs:
Condition: DeployDataCollectionComponents
Value: !GetAtt HeidiQSDataSource.Arn
Export:
Name: HeidiQSDataSourceArn
Name: !Sub ${ResourcePrefix}QSDataSourceArn
HeidiDataCollectionDB:
Condition: DeployDataCollectionComponents
Value: !Ref HeidiDataCollectionDB
Export:
Name: HeidiDataCollectionDB
Name: !Sub ${ResourcePrefix}DataCollectionDB

Conditions:
DataCollectionBucketKmsArn: !Not [!Equals [!Ref DataCollectionBucketKmsArn, "na"]]
Expand Down Expand Up @@ -350,7 +350,7 @@ Resources:
Properties:
CatalogId: !Sub '${AWS::AccountId}'
DatabaseInput:
Name: !Ref HeidiDataCollectionDB
Name: !Sub ${ResourcePrefix}${HeidiDataCollectionDB}
Description: "Heidi Data Collection Athena DB"

# Create an AWS QuickSight DataSource for DataCollection
Expand Down
6 changes: 4 additions & 2 deletions src/DataCollectionModule/HeidiRoot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"
EnableHealthModule:
Type: String
Description: Collects AWS Health data from different accounts and create quicksight analysis
Expand Down Expand Up @@ -151,6 +151,7 @@ Resources:
QuickSightAnalysisAuthor: !Ref QuickSightAnalysisAuthor
HeidiDataCollectionDB: !GetAtt DataCollectionModule.Outputs.HeidiDataCollectionDB
HeidiQSDataSourceArn: !GetAtt DataCollectionModule.Outputs.HeidiQSDataSourceArn
ResourcePrefix: !Ref ResourcePrefix

HealthModuleEventUrlSetup:
Type: AWS::CloudFormation::Stack
Expand Down Expand Up @@ -182,4 +183,5 @@ Resources:
Parameters:
QuickSightAnalysisAuthor: !Ref QuickSightAnalysisAuthor
QSDataSetHealthEvent: !GetAtt HealthModuleDataSetSetup.Outputs.QSDataSetHealthEvent
EventDetailUrl: !If [ EnableHealthEventUrl, !GetAtt HealthModuleEventUrlSetup.Outputs.EventDetailApiEndpoint, "https://example.com" ]
EventDetailUrl: !If [ EnableHealthEventUrl, !GetAtt HealthModuleEventUrlSetup.Outputs.EventDetailApiEndpoint, "https://example.com" ]
ResourcePrefix: !Ref ResourcePrefix
2 changes: 1 addition & 1 deletion src/HealthModule/HealthModuleCollectionSetup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"

Resources:
DataCollectionRuleRole:
Expand Down
38 changes: 21 additions & 17 deletions src/HealthModule/HealthModuleDataSetSetup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ Parameters:
HeidiDataCollectionDB:
Type: String
Description: Athena DataCollection DB
Default: "heididatacollectiondb"
Default: "datacollectiondb"
HeidiQSDataSourceArn:
Type: String
Description: Quick Sight Datasource Arn.
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "heidi-"

Outputs:
QSDataSetHealthEvent:
Value: !GetAtt QSDataSetHealthEvent.Arn
Export:
Name: !Sub ${ResourcePrefix}QSDataSetHealthEvent

Resources:
GlueHealthTable:
# AWS Glue Table resource representing AWS Health External Table
Type: AWS::Glue::Table
Properties:
# Reference to the AWS Glue Database
DatabaseName: !Ref HeidiDataCollectionDB
DatabaseName: !Sub ${ResourcePrefix}${HeidiDataCollectionDB}
CatalogId: !Sub '${AWS::AccountId}'
TableInput:
Name: awshealthevent
Expand Down Expand Up @@ -93,14 +103,14 @@ Resources:
Properties:
AwsAccountId: !Sub ${AWS::AccountId}
ImportMode: SPICE
DataSetId: !Sub "AWSHealthEvent-${AWS::AccountId}-${AWS::Region}"
Name: !Sub "AWSHealthEvent-${AWS::AccountId}-${AWS::Region}"
DataSetId: !Sub "${ResourcePrefix}${AWS::AccountId}-${AWS::Region}"
Name: !Sub "${ResourcePrefix}${AWS::AccountId}-${AWS::Region}"
PhysicalTableMap:
"AWSHealthQSPT":
CustomSql:
DataSourceArn: !Ref HeidiQSDataSourceArn
Name: !Sub "awshealthevents-${AWS::AccountId}-${AWS::Region}"
SqlQuery: |-
Name: !Sub "${ResourcePrefix}${AWS::AccountId}-${AWS::Region}"
SqlQuery: !Sub |-
WITH latestRow AS (
select * from (SELECT
detail.eventTypeCode,
Expand Down Expand Up @@ -139,7 +149,7 @@ Resources:
WHEN (detail.eventArn like '%PLANNED_LIFECYCLE_EVENT%') THEN 'Y'
ELSE 'N'
END AS "plannedLifeCycleEvent"
FROM "AwsDataCatalog"."heididatacollectiondb"."awshealthevent"
FROM "AwsDataCatalog"."${ResourcePrefix}${HeidiDataCollectionDB}"."awshealthevent"
LEFT JOIN UNNEST(detail.affectedEntities) AS t(entities) ON TRUE)
WHERE rowrank = 1),
tagInfo AS (select * from (
Expand All @@ -149,14 +159,14 @@ Resources:
'' as entityAZ,
tags.entitykey as entityTagKey,
tags.entityvalue as entityTagValue
FROM "AwsDataCatalog"."heididatacollectiondb"."taginfo", unnest(detail.tags) as t(tags)) where rowranktag =1)
FROM "AwsDataCatalog"."${ResourcePrefix}${HeidiDataCollectionDB}"."taginfo", unnest(detail.tags) as t(tags)) where rowranktag =1)
SELECT
detail.*,
taginfo.*,
COALESCE(accountinfo."name", detail."account") AS accountName,
accountinfo.Tag as accountTag
FROM latestRow detail
LEFT JOIN "AwsDataCatalog"."heididatacollectiondb"."accountsinfo" accountinfo ON detail.account = accountinfo."accountid"
LEFT JOIN "AwsDataCatalog"."${ResourcePrefix}${HeidiDataCollectionDB}"."accountsinfo" accountinfo ON detail.account = accountinfo."accountid"
LEFT JOIN tagInfo ON detail.affectedEntities in (taginfo.entityarn)
Columns:
- Name: eventTypeCode
Expand Down Expand Up @@ -271,15 +281,9 @@ Resources:
Type: AWS::QuickSight::RefreshSchedule
Properties:
AwsAccountId: !Sub ${AWS::AccountId}
DataSetId: !Sub "AWSHealthEvent-${AWS::AccountId}-${AWS::Region}"
DataSetId: !Sub "${ResourcePrefix}${AWS::AccountId}-${AWS::Region}"
Schedule:
RefreshType: FULL_REFRESH
ScheduleFrequency:
Interval: HOURLY
ScheduleId: QSDataSetHealthEventRefresh

Outputs:
QSDataSetHealthEvent:
Value: !GetAtt QSDataSetHealthEvent.Arn
Export:
Name: QSDataSetHealthEvent
ScheduleId: QSDataSetHealthEventRefresh
2 changes: 1 addition & 1 deletion src/HealthModule/HealthModuleEventUrlSetup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"
AllowedIpRange:
Default: "0.0.0.0/32"
Type: String
Expand Down
8 changes: 6 additions & 2 deletions src/HealthModule/HealthModuleQSAnalysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Parameters:
QuickSightAnalysisAuthor:
Type: String
Description: The QuickSight User that is allowed configure and manage the QS dashboard.
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "heidi-"
EventDetailUrl:
Type: String
Default: https://example.com
Expand All @@ -19,8 +23,8 @@ Resources:
Type: AWS::QuickSight::Analysis
Properties:
AwsAccountId: !Sub "${AWS::AccountId}"
Name: !Sub "HealthEvents-Analysis-${AWS::AccountId}-${AWS::Region}"
AnalysisId: !Sub "HealthEvents-Analysis-${AWS::AccountId}-${AWS::Region}"
Name: !Sub "${ResourcePrefix}Analysis-${AWS::AccountId}-${AWS::Region}"
AnalysisId: !Sub "${ResourcePrefix}Analysis-${AWS::AccountId}-${AWS::Region}"
Definition:
DataSetIdentifierDeclarations:
- Identifier: !Sub "AWSHealthEvent-${AWS::AccountId}-${AWS::Region}"
Expand Down
2 changes: 1 addition & 1 deletion src/HealthModule/HealthModuleTaginfoSetup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"
ResourceExplorerViewArn:
Type: String
Description: Provide Resource Explorer View Arn
Expand Down
2 changes: 1 addition & 1 deletion src/HealthModule/OrgHealthEventBackFill.Yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"

#This is one time execution of lamnda to backfill the events
Resources:
Expand Down
2 changes: 1 addition & 1 deletion src/NotificationModule/NotificationModule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Parameters:
ResourcePrefix:
Type: String
Description: This prefix will be placed in front of resources created where required. Note you may wish to add a dash at the end to make more readable
Default: "Heidi-"
Default: "heidi-"
SlackChannelId:
Type: String
Default: "na"
Expand Down
19 changes: 13 additions & 6 deletions src/Setup/utils/DataCollectionSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def get_user_input():
AWSOrganizationID = get_organization_details()
DataCollectionBucket, DataCollectionBucketKmsArn = create_or_get_s3_bucket(account_id, region)

ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (Heidi-): ") or "Heidi-"
ResourcePrefix = input("Enter ResourcePrefix (Must be in lowercase), Hit enter to use default (heidi-): ") or "heidi-"
ResourcePrefix = ResourcePrefix.lower()
print_boxed_text("Module Selection")
EnableHealthModule = ask_yes_no("Do you want to enable the AWS Health Module(HEIDI)?")
if EnableHealthModule:
Expand Down Expand Up @@ -372,12 +373,18 @@ def setup():
memberparameters = f"DataCollectionAccountID={parameters_dict['DataCollectionAccountID']} " \
f"DataCollectionRegion={parameters_dict['DataCollectionRegion']} " \
f"ResourcePrefix={parameters_dict['ResourcePrefix']} "

for memberregion in parameters_dict['MemberRegionHealth'].split(','):
Member_stack_name = f"{parameters_dict['ResourcePrefix']}HealthModule-{get_account_id()}-{memberregion}"
Membercommand = f"sam deploy --stack-name {Member_stack_name} --region {memberregion} --parameter-overrides {memberparameters} \
--template-file ../HealthModule/HealthModuleCollectionSetup.yaml --tags {tags} --capabilities CAPABILITY_NAMED_IAM --disable-rollback"
deploy_stack(Membercommand)
# Check if the memberregion is not empty or just whitespace
if memberregion.strip(): # This ensures that empty strings or whitespace regions are ignored
Member_stack_name = f"{parameters_dict['ResourcePrefix']}HealthModule-{get_account_id()}-{memberregion}"
Membercommand = f"sam deploy --stack-name {Member_stack_name} --region {memberregion} --parameter-overrides {memberparameters} \
--template-file ../HealthModule/HealthModuleCollectionSetup.yaml --tags {tags} --capabilities CAPABILITY_NAMED_IAM --disable-rollback"

# Deploy the stack
deploy_stack(Membercommand)
else:
print(f"Skipping member Region deployment, no member Region supplied.")

if __name__ == "__main__":
setup()
Expand Down
2 changes: 1 addition & 1 deletion src/Setup/utils/HealthEventBackFill.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

DataCollectionAccountID = input("Enter DataCollection Account ID: ")
DataCollectionRegion = input("Enter DataCollection region: ")
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (Heidi-): ") or "Heidi-"
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (heidi-): ") or "heidi-"

health_client = boto3.client('health', 'us-east-1')
eventbridge_client = boto3.client('events',DataCollectionRegion)
Expand Down
4 changes: 2 additions & 2 deletions src/Setup/utils/MemberSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_user_input():
print_boxed_text("Data Collection Account Parameters")
DataCollectionAccountID = input(f"Enter Data Collection Account ID, Default {get_account_id()}: ") or get_account_id()
DataCollectionRegion = input("Enter Data Collection Region ID: ")
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (Heidi-): ") or "Heidi-"
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (heidi-): ") or "heidi-"
return (
DataCollectionAccountID, DataCollectionRegion, DeploymentRegionHealth, ResourcePrefix
)
Expand All @@ -64,7 +64,7 @@ def setup():
ResourcePrefix={parameters_dict['ResourcePrefix']}"

for region in DeploymentRegionHealth.split(','):
stack_name = f"Heidi-HealthModule-{get_account_id()}-{region}"
stack_name = f"{parameters_dict['ResourcePrefix']}HealthModule-member-{get_account_id()}-{region}"
command = f"sam deploy --stack-name {stack_name} --region {region} --parameter-overrides {parameters} \
--template-file ../HealthModule/HealthModuleCollectionSetup.yaml --capabilities CAPABILITY_NAMED_IAM --disable-rollback"
# Deploy Stack
Expand Down
6 changes: 3 additions & 3 deletions src/Setup/utils/TagBackFill.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

DataCollectionAccountID = input("Enter DataCollection Account ID: ")
DataCollectionRegion = input("Enter DataCollection region: ")
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (Heidi-): ") or "Heidi-"
ResourceExplorerViewArn = input("Enter Resource explorere view ARN: ") or "arn:aws:resource-explorer-2:us-east-1:646279148361:view/index-test/203e04a0-2c88-4823-9291-c7e86f8c1478"
ResourcePrefix = input("Enter ResourcePrefix, Hit enter to use default (heidi-): ") or "heidi-"
ResourceExplorerViewArn = input("Enter Resource explorere view ARN: ")

eventbridge_client = boto3.client('events',DataCollectionRegion)
EventBusArnVal = f"arn:aws:events:{DataCollectionRegion}:{DataCollectionAccountID}:event-bus/{ResourcePrefix}DataCollectionBus-{DataCollectionAccountID}"
Expand All @@ -24,7 +24,7 @@ def resource_explorer():

# Define pagination configuration
pagination_config = {
'MaxItems': 100000, # Total maximum items to return across all pages
'MaxItems': 20000000, # Total maximum items to return across all pages
'PageSize': 1000 # Number of items per page
}

Expand Down

0 comments on commit 2030ffe

Please sign in to comment.