diff --git a/.gitignore b/.gitignore index 3158300..fd9ab72 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ .idea # Make -!environments/example.mvars environments/*.mvars # SAM Specific files diff --git a/Makefile b/Makefile index efb6786..e15ea20 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,16 @@ NC = \033[0m default:help; -appName=continuous-dev-environment +env?=dev + +include environments/$(env).mvars -region=us-east-1 -stack_name=$(appName) -profile=$(appName) -baseDomain=example.com -bucket=example-template-bucket -role=arn:aws:iam::ACCOUNTID:role/cloudformation-role -certificateArn=arn:aws:acm:us-east-1:ACCOUNTID:certificate/CERTIFICATEID -user=prenom.nom@continuous.team -roleSSO=continuous-team-sso-Role-ABCDEFG +appName=continuous-dev-environment +stack_name?=$(appName) +EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=m5.large" --query "Reservations[*].Instances[*].{Instance:InstanceId}" --output text) +WebappTargetGroup=$(shell aws cloudformation describe-stacks --profile $(profile) --stack-name $(appName) --region $(region) --query "Stacks[0].Outputs[?OutputKey=='WebappTargetGroup'].OutputValue" --output text) +ApiTargetGroup=$(shell aws cloudformation describe-stacks --profile $(profile) --stack-name $(appName) --region $(region) --query "Stacks[0].Outputs[?OutputKey=='ApiTargetGroup'].OutputValue" --output text) ## Display this help dialog help: @@ -55,6 +53,7 @@ deploy: --parameter-overrides BaseDomain=$(baseDomain) CertificateArn=$(certificateArn) \ User=$(user) RoleSSO=$(roleSSO) + ## Describe Cloud Formation stack outputs describe: @aws --profile $(profile) \ @@ -69,3 +68,15 @@ delete: --region $(region) \ cloudformation delete-stack \ --stack-name $(stack_name) + +target-group: + @aws elbv2 register-targets \ + --target-group-arn $(WebappTargetGroup) \ + --targets Id=$(EC2InstanceId) \ + --region $(region) \ + --profile $(profile) && echo "Instance is registered in webapp target group" + @aws elbv2 register-targets \ + --target-group-arn $(ApiTargetGroup) \ + --targets Id=$(EC2InstanceId) \ + --region $(region) \ + --profile $(profile) && echo "Instance is registered in Api target group" diff --git a/README.md b/README.md index 199f307..e575cd3 100644 --- a/README.md +++ b/README.md @@ -64,11 +64,17 @@ make package make deploy ``` +### after stack created + +Add your instance to a new target group. +The `target-group` Makefile rule may not work correctly if multiple m5.large instances are present in the targeted region (another m5.large instance may be picked up). Execute this BEFORE the final step. +```bash +make target-group +``` + ### finalize Manually change your cloud9 EC2 instance type to r5a.large. -To finalize the configuration connect to AWS console. -Go to EC2/LoadBlancing/targetGroup and add your instance to a new target group. ### Launch diff --git a/environments/dev.mvars.dist b/environments/dev.mvars.dist new file mode 100644 index 0000000..0db8b4f --- /dev/null +++ b/environments/dev.mvars.dist @@ -0,0 +1,8 @@ +bucket=example-template-bucket +role=arn:aws:iam::ACCOUNTID:role/administrative-cloudformation-role +certificateArn=arn:aws:acm:eu-west-1:ACCOUNTID:certificate/CERTIFICATEID +baseDomain=example.com +user=john@example.com +roleSSO=continuous-team-sso-Role-ABCDEFG +profile?=default +region?=us-east-1 diff --git a/library/load-balancer.yml b/library/load-balancer.yml index 5674650..e7424b5 100644 --- a/library/load-balancer.yml +++ b/library/load-balancer.yml @@ -140,3 +140,12 @@ Outputs: DNSName: Description: ALB Hostname Value: !GetAtt Alb.DNSName + Alb: + Description: Alb + Value: !Ref Alb + ApiTargetGroup: + Description: ApiTargetGroup + Value: !Ref ApiTargetGroup + WebappTargetGroup: + Description: WebappTargetGroup + Value: !Ref WebappTargetGroup diff --git a/template.yml b/template.yml index 81b571a..fb20439 100644 --- a/template.yml +++ b/template.yml @@ -54,3 +54,12 @@ Resources: Name: !Ref AWS::StackName SubnetId: !GetAtt VpcStack.Outputs.Subnet1 OwnerArn: !Sub 'arn:aws:sts::${AWS::AccountId}:assumed-role/${RoleSSO}/${User}' + + +Outputs: + WebappTargetGroup: + Description: WebappTargetGroup + Value: !GetAtt LoadBalancerStack.Outputs.WebappTargetGroup + ApiTargetGroup: + Description: ApiTargetGroup + Value: !GetAtt LoadBalancerStack.Outputs.ApiTargetGroup