Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/DataCollectionModule/DataCollectionModule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Parameters:
Outputs:
HeidiQSDataSourceArn:
Condition: DeployDataCollectionComponents
Value: !GetAtt HeidiQSDataSource.Arn
Value: !GetAtt HeidiQSDataSourceV2.Arn
Export:
Name: !Sub ${ResourcePrefix}QSDataSourceArn
HeidiDataCollectionDB:
Expand Down Expand Up @@ -352,7 +352,7 @@ Resources:
Description: "Heidi Data Collection Athena DB"

# Create an AWS QuickSight DataSource for DataCollection
HeidiQSDataSource:
HeidiQSDataSourceV2:
Condition: DeployDataCollectionComponents
Type: AWS::QuickSight::DataSource
Properties:
Expand Down
45 changes: 33 additions & 12 deletions src/Setup/utils/DataCollectionSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,33 @@

# Get Tag
def tag():
# Get the default AWS region from the current session
tag_key = input("Enter the key to tag the stack (Hit enter to use default: 'App'): ") or "App"
"""Get multiple tag key-value pairs from user input"""
tags = {}

# Get the first tag with defaults
tag_key = input("Enter the first tag key (Hit enter to use default: 'App'): ") or "App"
tag_value = input(f"Enter the value for '{tag_key}' (Hit enter to use default: 'Heidi'): ") or "Heidi"
return tag_key, tag_value


# Call the tag function to get the tag key and value
tag_key, tag_value = tag()
tags[tag_key] = tag_value

# Allow user to add more tags
while True:
add_more = input("Do you want to add another tag? (yes/no): ").lower().strip()
if add_more in ['yes', 'y']:
tag_key = input("Enter tag key: ").strip()
if tag_key:
tag_value = input(f"Enter value for '{tag_key}': ").strip()
tags[tag_key] = tag_value
else:
print("Tag key cannot be empty. Skipping...")
elif add_more in ['no', 'n']:
break
else:
print("Invalid input. Please enter 'yes' or 'no'.")

return tags

# Initialize tags_dict - will be populated in setup()
tags_dict = {}

#Get Current Region
def get_default_region():
Expand Down Expand Up @@ -76,11 +94,11 @@ def create_or_get_s3_bucket(account_id, region):
print(f"S3 bucket {bucket_name} has been created")

# Add tags to the newly created bucket
tagging = {
'TagSet': [{'Key': tag_key, 'Value': tag_value},]}
tag_set = [{'Key': key, 'Value': value} for key, value in tags_dict.items()]
tagging = {'TagSet': tag_set}

s3_client.put_bucket_tagging(Bucket=bucket_name, Tagging=tagging)
print(f"Tags added to bucket {bucket_name}")
print(f"Tags added to bucket {bucket_name}: {tags_dict}")

return bucket_name, bucketkmsarn

Expand Down Expand Up @@ -313,6 +331,10 @@ def read_parameters(file_path):
}

def setup():
# Get tag information from user
global tags_dict
tags_dict = tag()

file_path = 'utils/ParametersDataCollection.txt'

if os.path.exists(file_path):
Expand Down Expand Up @@ -355,8 +377,7 @@ def setup():
f"EnableNotificationModule={parameters_dict['EnableNotificationModule']} "

#Update tags here
# Call the tag function to get the tag key and value
tags = f"{tag_key}={tag_value} "
tags = " ".join([f"{key}={value}" for key, value in tags_dict.items()])

command= f"sam deploy --stack-name {stack_name} --region {parameters_dict['DataCollectionRegion']} --parameter-overrides {parameters}\
--template-file ../DataCollectionModule/HeidiRoot.yaml --tags {tags} --capabilities CAPABILITY_NAMED_IAM --disable-rollback"
Expand Down
40 changes: 38 additions & 2 deletions src/Setup/utils/MemberSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
from botocore.exceptions import ClientError
import os

# Get Tag
def tag():
"""Get multiple tag key-value pairs from user input"""
tags = {}

# Get the first tag with defaults
tag_key = input("Enter the first tag key (Hit enter to use default: 'App'): ") or "App"
tag_value = input(f"Enter the value for '{tag_key}' (Hit enter to use default: 'Heidi'): ") or "Heidi"
tags[tag_key] = tag_value

# Allow user to add more tags
while True:
add_more = input("Do you want to add another tag? (yes/no): ").lower().strip()
if add_more in ['yes', 'y']:
tag_key = input("Enter tag key: ").strip()
if tag_key:
tag_value = input(f"Enter value for '{tag_key}': ").strip()
tags[tag_key] = tag_value
else:
print("Tag key cannot be empty. Skipping...")
elif add_more in ['no', 'n']:
break
else:
print("Invalid input. Please enter 'yes' or 'no'.")

return tags

# Initialize tags_dict - will be populated in setup()
tags_dict = {}

# Get Current Account ID
def get_account_id():
# Get the AWS account ID for Unique names
Expand Down Expand Up @@ -31,7 +61,6 @@ def print_boxed_text(text):
print(f' {line.ljust(max_length)} ')
print('═' * (max_length + 2))


# deploy stack
def deploy_stack(command):
try:
Expand All @@ -52,6 +81,10 @@ def get_user_input():

# setup
def setup():
# Get tag information from user
global tags_dict
tags_dict = tag()

parameters_dict = {}
DataCollectionAccountID, DataCollectionRegion, DeploymentRegionHealth, ResourcePrefix = get_user_input()

Expand All @@ -63,10 +96,13 @@ def setup():
DataCollectionRegion={parameters_dict['DataCollectionRegion']} \
ResourcePrefix={parameters_dict['ResourcePrefix']}"

# Format tags for deployment
tags = " ".join([f"{key}={value}" for key, value in tags_dict.items()])

for region in DeploymentRegionHealth.split(','):
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"
--template-file ../HealthModule/HealthModuleCollectionSetup.yaml --tags {tags} --capabilities CAPABILITY_NAMED_IAM --disable-rollback"
# Deploy Stack
deploy_stack(command)

Expand Down