From 292df38ce7b83a5b5102bb346ec38ca55054f415 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Thu, 2 Jul 2020 18:53:14 +0200 Subject: [PATCH 01/14] add aws command which register target --- Makefile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index efb6786..fd3362e 100644 --- a/Makefile +++ b/Makefile @@ -8,14 +8,17 @@ appName=continuous-dev-environment 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 +profile=default +baseDomain=farouk.continuous.team +bucket=init-stack-templatebucket-129d6fp5mdj5d +role=arn:aws:iam::841723950712:role/cloudformation-cloud9-role +certificateArn=arn:aws:acm:us-east-1:841723950712:certificate/1ba88a5b-5c0e-402a-abff-dec28d93ba5a +user=farouk.lamri@continuous.team +roleSSO=AWSReservedSSO_SandboxAccess_f08a32026a2f2008 +EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=r5a.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 +58,7 @@ deploy: --parameter-overrides BaseDomain=$(baseDomain) CertificateArn=$(certificateArn) \ User=$(user) RoleSSO=$(roleSSO) + ## Describe Cloud Formation stack outputs describe: @aws --profile $(profile) \ @@ -69,3 +73,7 @@ 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) + aws elbv2 register-targets --target-group-arn $(ApiTargetGroup) --targets Id=$(EC2InstanceId) --region $(region) --profile $(profile) From 9b2029d51ddb021b342b1ec99253f5428b32c456 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Thu, 2 Jul 2020 18:53:42 +0200 Subject: [PATCH 02/14] add target group output --- library/load-balancer.yml | 9 +++++++++ 1 file changed, 9 insertions(+) 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 From 0286be84a7c1dee6876d0ab9b2704ef54ca9dc22 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Thu, 2 Jul 2020 18:54:02 +0200 Subject: [PATCH 03/14] output target group info --- template.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/template.yml b/template.yml index 81b571a..54873ab 100644 --- a/template.yml +++ b/template.yml @@ -14,7 +14,7 @@ Parameters: Cloud9InstanceType: Description: Cloud9 EC2 Instance Type Type: String - Default: m5.large + Default: m5a.large RoleSSO: Description: Federation Role Name Type: String @@ -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 From 7aa82519f8f27c5699b86ffb068c0963e5b1a47a Mon Sep 17 00:00:00 2001 From: Farouk-Lamri <58430340+Farouk-Lamri@users.noreply.github.com> Date: Fri, 3 Jul 2020 10:54:34 +0200 Subject: [PATCH 04/14] Update Makefile --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index fd3362e..3bb14dd 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,13 @@ appName=continuous-dev-environment region=us-east-1 stack_name=$(appName) -profile=default -baseDomain=farouk.continuous.team -bucket=init-stack-templatebucket-129d6fp5mdj5d -role=arn:aws:iam::841723950712:role/cloudformation-cloud9-role -certificateArn=arn:aws:acm:us-east-1:841723950712:certificate/1ba88a5b-5c0e-402a-abff-dec28d93ba5a -user=farouk.lamri@continuous.team -roleSSO=AWSReservedSSO_SandboxAccess_f08a32026a2f2008 +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 EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=r5a.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) From f9442ac56cd12ddfcc734a0fa8c642f8b6ac0e5d Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 11:29:51 +0200 Subject: [PATCH 05/14] add dist config file with needed variable aws infos and import it in makefile --- Makefile | 9 ++------- environments/config.mvars.dist | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 environments/config.mvars.dist diff --git a/Makefile b/Makefile index fd3362e..0e6cd04 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,12 @@ NC = \033[0m default:help; -appName=continuous-dev-environment +include environments/config.mvars +appName=continuous-dev-environment region=us-east-1 stack_name=$(appName) profile=default -baseDomain=farouk.continuous.team -bucket=init-stack-templatebucket-129d6fp5mdj5d -role=arn:aws:iam::841723950712:role/cloudformation-cloud9-role -certificateArn=arn:aws:acm:us-east-1:841723950712:certificate/1ba88a5b-5c0e-402a-abff-dec28d93ba5a -user=farouk.lamri@continuous.team -roleSSO=AWSReservedSSO_SandboxAccess_f08a32026a2f2008 EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=r5a.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) diff --git a/environments/config.mvars.dist b/environments/config.mvars.dist new file mode 100644 index 0000000..0db8b4f --- /dev/null +++ b/environments/config.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 From a738e1067baeb26a568aa9162a371d25c529b100 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 11:30:28 +0200 Subject: [PATCH 06/14] delete rule with example.mvars --- .gitignore | 1 - 1 file changed, 1 deletion(-) 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 From 773438baf68cc4a13a772d803bdcbcae4bc335c0 Mon Sep 17 00:00:00 2001 From: gkdg Date: Fri, 3 Jul 2020 11:58:37 +0200 Subject: [PATCH 07/14] makefile env variables now importable --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 0e6cd04..5ad80b2 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ NC = \033[0m default:help; -include environments/config.mvars +env?=dev + +include environments/$(env).mvars appName=continuous-dev-environment -region=us-east-1 -stack_name=$(appName) -profile=default +stack_name?=$(appName) EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=r5a.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) From 0e8273c57fe67b4a4ceb259ea5ea41df8ed45b55 Mon Sep 17 00:00:00 2001 From: gkdg Date: Fri, 3 Jul 2020 12:01:50 +0200 Subject: [PATCH 08/14] config.mvars.dist renamed to dev.mvars.dist --- environments/{config.mvars.dist => dev.mvars.dist} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename environments/{config.mvars.dist => dev.mvars.dist} (100%) diff --git a/environments/config.mvars.dist b/environments/dev.mvars.dist similarity index 100% rename from environments/config.mvars.dist rename to environments/dev.mvars.dist From 7777be0f00ac69e178e8a26a44bd8d4f74b3300d Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 14:32:38 +0200 Subject: [PATCH 09/14] update instance type --- Makefile | 2 +- template.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0e6cd04..fb65325 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ region=us-east-1 stack_name=$(appName) profile=default -EC2InstanceId=$(shell aws ec2 describe-instances --profile $(profile) --region $(region) --filters "Name=instance-type,Values=r5a.large" --query "Reservations[*].Instances[*].{Instance:InstanceId}" --output text) +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) diff --git a/template.yml b/template.yml index 54873ab..fb20439 100644 --- a/template.yml +++ b/template.yml @@ -14,7 +14,7 @@ Parameters: Cloud9InstanceType: Description: Cloud9 EC2 Instance Type Type: String - Default: m5a.large + Default: m5.large RoleSSO: Description: Federation Role Name Type: String From 9920e0e553cee3685a39bab1ff3ffbfa2d15abd6 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 14:40:04 +0200 Subject: [PATCH 10/14] formatting target-group command --- Makefile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fb65325..fc47a89 100644 --- a/Makefile +++ b/Makefile @@ -70,5 +70,13 @@ delete: --stack-name $(stack_name) target-group: - aws elbv2 register-targets --target-group-arn $(WebappTargetGroup) --targets Id=$(EC2InstanceId) --region $(region) --profile $(profile) - aws elbv2 register-targets --target-group-arn $(ApiTargetGroup) --targets Id=$(EC2InstanceId) --region $(region) --profile $(profile) + aws elbv2 register-targets \ + --target-group-arn $(WebappTargetGroup) \ + --targets Id=$(EC2InstanceId) \ + --region $(region) \ + --profile $(profile) + aws elbv2 register-targets \ + --target-group-arn $(ApiTargetGroup) \ + --targets Id=$(EC2InstanceId) \ + --region $(region) \ + --profile $(profile) From f828fa41bc1a9b62f32d77f3132d2bfb33032e32 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 14:47:23 +0200 Subject: [PATCH 11/14] update readme for target group --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 199f307..3f82dc7 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. + +```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 From 61b39115ecc66f45fa17598a95dcac169714eefa Mon Sep 17 00:00:00 2001 From: Farouk-Lamri <58430340+Farouk-Lamri@users.noreply.github.com> Date: Fri, 3 Jul 2020 19:34:37 +0200 Subject: [PATCH 12/14] Update README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Raphaƫl Schumacher <48203929+RSchumacher13@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f82dc7..9bf61c7 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ 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 finalize step. ```bash make target-group ``` From e05fdd8b4c460aeb481aa1020cf7ff707ca05076 Mon Sep 17 00:00:00 2001 From: Farouk Lamri Date: Fri, 3 Jul 2020 20:05:49 +0200 Subject: [PATCH 13/14] add successfullmessage to target group --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6169d2a..d319edc 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ env?=dev include environments/$(env).mvars -appName=continuous-dev-environment +appName=continuous-dev-environment-1 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) @@ -74,9 +74,9 @@ target-group: --target-group-arn $(WebappTargetGroup) \ --targets Id=$(EC2InstanceId) \ --region $(region) \ - --profile $(profile) + --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) + --profile $(profile) && echo "Instance is registered in Api target group" From d0a1f10175b4140ec09df5c9ecdb980049340c57 Mon Sep 17 00:00:00 2001 From: gkdg Date: Sun, 5 Jul 2020 10:03:38 +0200 Subject: [PATCH 14/14] target-group does not print the commands and a small wording change on readme --- Makefile | 6 +++--- README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d319edc..e15ea20 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ env?=dev include environments/$(env).mvars -appName=continuous-dev-environment-1 +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) @@ -70,12 +70,12 @@ delete: --stack-name $(stack_name) target-group: - aws elbv2 register-targets \ + @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 \ + @aws elbv2 register-targets \ --target-group-arn $(ApiTargetGroup) \ --targets Id=$(EC2InstanceId) \ --region $(region) \ diff --git a/README.md b/README.md index 9bf61c7..e575cd3 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ 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 finalize step. +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 ```