Skip to content

Commit

Permalink
Add core url to SM, remove optout references
Browse files Browse the repository at this point in the history
  • Loading branch information
abuabraham-ttd committed Dec 17, 2024
1 parent 9305ba2 commit 50d1ada
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions scripts/aws/create_cloudformation_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ def create_egress(url, description):
def get_port(url):
return url.split(":")[1]

def create_cloudformation_stack(client, stack_name, cft_content, api_token, dc_cfg, ip_address):
def create_cloudformation_stack(client, stack_name, cft_content, api_token, core_base_url, dc_cfg, ip_address):
result = client.create_stack(
StackName=stack_name,
TemplateBody=cft_content,
Capabilities=['CAPABILITY_IAM'],
Parameters=[
{ 'ParameterKey': 'APIToken', 'ParameterValue': api_token },
{ 'ParameterKey': 'DeployToEnvironment', 'ParameterValue': 'integ' },
{ 'ParameterKey': 'CoreBaseURL', 'ParameterValue': core_base_url },
{ 'ParameterKey': 'DeployToEnvironment', 'ParameterValue': 'integ' },
{ 'ParameterKey': 'VpcId', 'ParameterValue': dc_cfg['VpcId'] },
{ 'ParameterKey': 'VpcSubnet1', 'ParameterValue': dc_cfg['VpcSubnet1'] },
{ 'ParameterKey': 'VpcSubnet2', 'ParameterValue': dc_cfg['VpcSubnet2'] },
Expand All @@ -39,7 +40,6 @@ def create_cloudformation_stack(client, stack_name, cft_content, api_token, dc_c
parser.add_argument('--stack_fp', dest='stack_fp', action='store', required='true', help='The filepath to the AWS stacks')
parser.add_argument('--cftemplate_fp', dest='cftemplate_fp', action='store', required='true', help='The filepath to the CloudFormation template')
parser.add_argument('--core_url', dest='core_url', action='store', required='true', help='The core URL')
parser.add_argument('--optout_url', dest='optout_url', action='store', required='true', help='The optout URL')
parser.add_argument('--localstack_url', dest='localstack_url', action='store', required='true', help='The localstack URL')
parser.add_argument('--region', choices=['us-east-1', 'us-west-1', 'ca-central-1', 'eu-central-1'], dest='region', action='store', required='true', help='The AWS target region')
parser.add_argument('--ami', dest='ami', action='store', required='true', help='The AMI ID')
Expand All @@ -58,15 +58,12 @@ def create_cloudformation_stack(client, stack_name, cft_content, api_token, dc_c

egress = cft['Resources']['SecurityGroup']['Properties']['SecurityGroupEgress']
egress.append(create_egress(args.core_url, 'E2E - Core'))
egress.append(create_egress(args.optout_url, 'E2E - Optout'))
egress.append(create_egress(args.localstack_url, 'E2E - Localstack'))
cft['Resources']['SecurityGroup']['Properties']['SecurityGroupEgress'] = egress

user_data = cft['Resources']['LaunchTemplate']['Properties']['LaunchTemplateData']['UserData']['Fn::Base64']['Fn::Sub']
first_line = user_data.find('\n')
user_data = user_data[:first_line] + '''
export CORE_BASE_URL="http://{}"
export OPTOUT_BASE_URL="http://{}"'''.format(args.core_url, args.optout_url) + user_data[first_line:]
user_data = user_data[:first_line] + user_data[first_line:]
cft['Resources']['LaunchTemplate']['Properties']['LaunchTemplateData']['UserData']['Fn::Base64']['Fn::Sub'] = user_data

print(dump_yaml(cft))
Expand All @@ -78,5 +75,6 @@ def create_cloudformation_stack(client, stack_name, cft_content, api_token, dc_c
stack_name=args.stack,
cft_content=dump_yaml(cft),
api_token=args.operator_key,
core_base_url = args.core_url,
dc_cfg=dc_cfg,
ip_address=ip)

0 comments on commit 50d1ada

Please sign in to comment.