Adding the Route 53 samples
Showing
15 changed files
with
108 additions
and
25 deletions
... | @@ -28,13 +28,13 @@ The presentation could be found [here](https://docs.google.com/presentation/d/1Z | ... | @@ -28,13 +28,13 @@ The presentation could be found [here](https://docs.google.com/presentation/d/1Z |
28 | 28 | ||
29 | 1. Moving deployment script into temlplate provider | 29 | 1. Moving deployment script into temlplate provider |
30 | 2. Using *length()* function to get size and create multiple resources | 30 | 2. Using *length()* function to get size and create multiple resources |
31 | 3. Add IAM profile for instance | ||
31 | 32 | ||
32 | ### Sample5. Scaling our applications, adding scaling policies | 33 | ### Sample5. Scaling our applications, adding scaling policies |
33 | 34 | ||
34 | 1. Add IAM profile for instance | 35 | 1. Creating launch configuration, autoscaling grops |
35 | 2. Creating launch configuration, autoscaling grops | 36 | 2. Building module |
36 | 3. Building module | 37 | 3. Dealing with LoadBalancers and Certificates |
37 | 4. Dealing with LoadBalancers and http | ||
38 | 38 | ||
39 | ### AppendixA. Upgrading applications environment | 39 | ### AppendixA. Upgrading applications environment |
40 | 1. Blue/Green deployment | 40 | 1. Blue/Green deployment | ... | ... |
sample1/sample1.png
0 → 100644
34.3 KB
sample2/sample2.png
0 → 100644
68.7 KB
sample3/sample3.png
0 → 100644
103 KB
sample4/iam.tf
0 → 100644
1 | ## Define a policy to RO | ||
2 | resource "aws_iam_policy" "ec2-ro-policy" { | ||
3 | name = "ec2-ro-policy" | ||
4 | path = "/" | ||
5 | description = "Autocreated Policy to read tags from ec2 instance" | ||
6 | policy = <<EOF | ||
7 | { | ||
8 | "Version": "2012-10-17", | ||
9 | "Statement": [ | ||
10 | { | ||
11 | "Sid": "Stmt1506366968000", | ||
12 | "Effect": "Allow", | ||
13 | "Action": [ | ||
14 | "ec2:DescribeInstances", | ||
15 | "ec2:DescribeTags" | ||
16 | ], | ||
17 | "Resource": [ | ||
18 | "*" | ||
19 | ] | ||
20 | } | ||
21 | ] | ||
22 | } | ||
23 | EOF | ||
24 | } | ||
25 | |||
26 | ## STS AssumeRole Data | ||
27 | data "aws_iam_policy_document" "instance-assume-role-policy" { | ||
28 | statement { | ||
29 | actions = ["sts:AssumeRole"] | ||
30 | principals { | ||
31 | type = "Service" | ||
32 | identifiers = ["ec2.amazonaws.com"] | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | ## Add EC2 instance role | ||
38 | resource "aws_iam_role" "ec2-instance-role" { | ||
39 | name = "ec2-instance-role" | ||
40 | path = "/" | ||
41 | assume_role_policy = "${data.aws_iam_policy_document.instance-assume-role-policy.json}" | ||
42 | } | ||
43 | |||
44 | ## Attach policy to role | ||
45 | resource "aws_iam_policy_attachment" "ec2-policy-attachemnt" { | ||
46 | name = "ec2-policy-attachemnt" | ||
47 | roles = ["${aws_iam_role.ec2-instance-role.name}"] | ||
48 | policy_arn = "${aws_iam_policy.ec2-ro-policy.arn}" | ||
49 | } | ||
50 | |||
51 | ## Create instance profile and attah the role | ||
52 | resource "aws_iam_instance_profile" "ec2-instance-profile" { | ||
53 | name = "ec2-instance-profile" | ||
54 | role = "${aws_iam_role.ec2-instance-role.name}" | ||
55 | } | ||
56 |
sample4/sample4.png
0 → 100644
164 KB
... | @@ -16,5 +16,5 @@ default_db_subnet_group_subnet_ids = { | ... | @@ -16,5 +16,5 @@ default_db_subnet_group_subnet_ids = { |
16 | eu-west-1 = [ "subnet-f1e92d8a", "subnet-304b7f7a" ] | 16 | eu-west-1 = [ "subnet-f1e92d8a", "subnet-304b7f7a" ] |
17 | } | 17 | } |
18 | 18 | ||
19 | # | 19 | # Define instance suffix |
20 | instance_suffix = ["a","b"] | 20 | instance_suffix = ["blue","green"] | ... | ... |
... | @@ -8,12 +8,29 @@ module "m-elb-xpdays" { | ... | @@ -8,12 +8,29 @@ module "m-elb-xpdays" { |
8 | backend_port = "3334" | 8 | backend_port = "3334" |
9 | backend_protocol = "http" | 9 | backend_protocol = "http" |
10 | 10 | ||
11 | # ssl_certificate_id = "${data.aws_acm_certificate.wisehands.me.arn}" | 11 | ssl_certificate_id = "${data.aws_acm_certificate.star-shalb-com.arn}" |
12 | health_check_target = "HTTP:3334/" | 12 | health_check_target = "HTTP:3334/" |
13 | 13 | ||
14 | # elb_security_group = "${aws_security_group.elb-sg.id}" | 14 | # elb_security_group = "${aws_security_group.elb-sg.id}" |
15 | } | 15 | } |
16 | 16 | ||
17 | # Get the certificate assigned | ||
18 | data "aws_acm_certificate" "star-shalb-com" { | ||
19 | domain = "*.aws.shalb.com" | ||
20 | statuses = ["ISSUED"] | ||
21 | |||
22 | } | ||
23 | |||
24 | # Attach the domain to ELB | ||
25 | |||
26 | resource "aws_route53_record" "xpdays-aws-shalb-com" { | ||
27 | zone_id = "Z36XQDCMS0HHZM" | ||
28 | name = "xpdays.aws.shalb.com" | ||
29 | type = "CNAME" | ||
30 | ttl = "300" | ||
31 | records = ["${module.m-elb-xpdays.elb_dns_name}"] | ||
32 | } | ||
33 | |||
17 | ## Add rule for access to ELB SG into default SG | 34 | ## Add rule for access to ELB SG into default SG |
18 | resource "aws_security_group_rule" "allow_3334_xpdays" { | 35 | resource "aws_security_group_rule" "allow_3334_xpdays" { |
19 | type = "ingress" | 36 | type = "ingress" | ... | ... |
... | @@ -4,13 +4,13 @@ resource "aws_elb" "elb" { | ... | @@ -4,13 +4,13 @@ resource "aws_elb" "elb" { |
4 | internal = "${var.elb_is_internal}" | 4 | internal = "${var.elb_is_internal}" |
5 | security_groups = ["${aws_security_group.elb-sg.id}"] | 5 | security_groups = ["${aws_security_group.elb-sg.id}"] |
6 | 6 | ||
7 | # listener { | 7 | listener { |
8 | # instance_port = "${var.backend_port}" | 8 | instance_port = "${var.backend_port}" |
9 | # instance_protocol = "${var.backend_protocol}" | 9 | instance_protocol = "${var.backend_protocol}" |
10 | # lb_port = 443 | 10 | lb_port = 443 |
11 | # lb_protocol = "https" | 11 | lb_protocol = "https" |
12 | # # ssl_certificate_id = "${var.ssl_certificate_id}" | 12 | ssl_certificate_id = "${var.ssl_certificate_id}" |
13 | # } | 13 | } |
14 | 14 | ||
15 | listener { | 15 | listener { |
16 | instance_port = "${var.backend_port}" | 16 | instance_port = "${var.backend_port}" | ... | ... |
... | @@ -13,9 +13,9 @@ variable "elb_is_internal" { | ... | @@ -13,9 +13,9 @@ variable "elb_is_internal" { |
13 | 13 | ||
14 | // See README.md for details on finding the | 14 | // See README.md for details on finding the |
15 | // ARN of an SSL certificate in EC2 | 15 | // ARN of an SSL certificate in EC2 |
16 | #variable "ssl_certificate_id" { | 16 | variable "ssl_certificate_id" { |
17 | # description = "The ARN of the SSL Certificate in EC2" | 17 | description = "The ARN of the SSL Certificate in EC2" |
18 | #} | 18 | } |
19 | 19 | ||
20 | variable "subnet_az1" { | 20 | variable "subnet_az1" { |
21 | description = "The subnet for AZ1" | 21 | description = "The subnet for AZ1" | ... | ... |
... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
2 | hostname ${instancehostname} && hostname > /etc/hostname | 2 | hostname ${instancehostname} && hostname > /etc/hostname |
3 | echo "127.0.0.1 localhost `hostname`" > /etc/hosts | 3 | echo "127.0.0.1 localhost `hostname`" > /etc/hosts |
4 | cd /home/ubuntu | 4 | cd /home/ubuntu |
5 | git clone https://bitbucket.org/bohdaq/wisehands.me.git | 5 | git clone --branch ${versiontag} https://bitbucket.org/bohdaq/wisehands.me.git |
6 | cd /home/ubuntu/wisehands.me/ && play deps | 6 | cd /home/ubuntu/wisehands.me/ && play deps |
7 | mkdir -p /home/ubuntu/wisehands.me/modules/guice-1.2 | 7 | mkdir -p /home/ubuntu/wisehands.me/modules/guice-1.2 |
8 | cd /home/ubuntu/wisehands.me/modules/guice-1.2 | 8 | cd /home/ubuntu/wisehands.me/modules/guice-1.2 | ... | ... |
... | @@ -6,6 +6,7 @@ data "template_file" "init" { | ... | @@ -6,6 +6,7 @@ data "template_file" "init" { |
6 | vars { | 6 | vars { |
7 | dbendpoint="${aws_db_instance.db-instance.username}:${aws_db_instance.db-instance.password}@${aws_db_instance.db-instance.endpoint}\\/${aws_db_instance.db-instance.name}" | 7 | dbendpoint="${aws_db_instance.db-instance.username}:${aws_db_instance.db-instance.password}@${aws_db_instance.db-instance.endpoint}\\/${aws_db_instance.db-instance.name}" |
8 | instancehostname="xpdays-${var.instance_suffix[count.index]}-${count.index}" | 8 | instancehostname="xpdays-${var.instance_suffix[count.index]}-${count.index}" |
9 | versiontag="${var.xpdays_versiontag}" | ||
9 | } | 10 | } |
10 | } | 11 | } |
11 | 12 | ||
... | @@ -23,19 +24,19 @@ resource "aws_launch_configuration" "launch-xpdays" { | ... | @@ -23,19 +24,19 @@ resource "aws_launch_configuration" "launch-xpdays" { |
23 | 24 | ||
24 | ## Add Autoscaling group | 25 | ## Add Autoscaling group |
25 | resource "aws_autoscaling_group" "asg-xpdays" { | 26 | resource "aws_autoscaling_group" "asg-xpdays" { |
26 | # lifecycle { create_before_destroy = true } | 27 | lifecycle { create_before_destroy = true } |
27 | # depends_on = ["aws_launch_configuration.launch-xpdays"] | 28 | name = "asg-${aws_launch_configuration.launch-xpdays.name}-${var.instance_suffix[count.index]}" |
29 | |||
28 | desired_capacity = "${lookup(var.instance_count_xpdays_desired, var.environment)}" | 30 | desired_capacity = "${lookup(var.instance_count_xpdays_desired, var.environment)}" |
29 | max_size = "${lookup(var.instance_count_xpdays_max, var.environment)}" | 31 | max_size = "${lookup(var.instance_count_xpdays_max, var.environment)}" |
30 | min_size = "${lookup(var.instance_count_xpdays_min, var.environment)}" | 32 | min_size = "${lookup(var.instance_count_xpdays_min, var.environment)}" |
31 | health_check_grace_period = 300 | 33 | health_check_grace_period = 300 |
32 | health_check_type = "EC2" | 34 | health_check_type = "EC2" |
33 | launch_configuration = "${element(aws_launch_configuration.launch-xpdays.*.name, count.index)}" | 35 | launch_configuration = "${element(aws_launch_configuration.launch-xpdays.*.name, count.index)}" |
34 | name = "asg-xpdays-${var.instance_suffix[count.index]}" | ||
35 | vpc_zone_identifier = ["${list(aws_subnet.default_subnet.id)}"] | 36 | vpc_zone_identifier = ["${list(aws_subnet.default_subnet.id)}"] |
36 | availability_zones = ["${lookup(var.default_subnet_availability_zone, var.environment)}"] | 37 | availability_zones = ["${lookup(var.default_subnet_availability_zone, var.environment)}"] |
37 | load_balancers = ["${module.m-elb-xpdays.elb_id}"] | 38 | load_balancers = ["${module.m-elb-xpdays.elb_id}"] |
38 | # wait_for_elb_capacity = "${element(var.instance_count_xpdays_desired[var.environment],count.index)}" | 39 | wait_for_elb_capacity = "${lookup(var.instance_count_xpdays_min, var.environment)}" |
39 | enabled_metrics = "${var.asg_enabled_metrics}" | 40 | enabled_metrics = "${var.asg_enabled_metrics}" |
40 | tag { | 41 | tag { |
41 | key = "Name" | 42 | key = "Name" | ... | ... |
sample5/sample5.png
0 → 100644
684 KB
1 | ## Define the microservice version | ||
2 | |||
3 | xpdays_versiontag = "0.0.2" | ||
4 | |||
1 | ### AWS related | 5 | ### AWS related |
2 | 6 | ||
3 | region = { | 7 | region = { |
... | @@ -44,7 +48,8 @@ asg_enabled_metrics = [ "GroupDesiredCapacity", "GroupPendingInstances", "GroupI | ... | @@ -44,7 +48,8 @@ asg_enabled_metrics = [ "GroupDesiredCapacity", "GroupPendingInstances", "GroupI |
44 | "GroupStandbyInstances", "GroupTotalInstances", "GroupMinSize" , "GroupTerminatingInstances" ] | 48 | "GroupStandbyInstances", "GroupTotalInstances", "GroupMinSize" , "GroupTerminatingInstances" ] |
45 | 49 | ||
46 | # | 50 | # |
47 | instance_suffix = ["blue","green"] | 51 | instance_suffix = ["blue"] |
52 | #instance_suffix = ["blue","green"] | ||
48 | 53 | ||
49 | 54 | ||
50 | instance_count_xpdays_desired = { | 55 | instance_count_xpdays_desired = { |
... | @@ -52,7 +57,7 @@ instance_count_xpdays_desired = { | ... | @@ -52,7 +57,7 @@ instance_count_xpdays_desired = { |
52 | development = 1 | 57 | development = 1 |
53 | } | 58 | } |
54 | instance_count_xpdays_min = { | 59 | instance_count_xpdays_min = { |
55 | production = 0 | 60 | production = 1 |
56 | development = 1 | 61 | development = 1 |
57 | } | 62 | } |
58 | instance_count_xpdays_max = { | 63 | instance_count_xpdays_max = { | ... | ... |
-
Please register or sign in to post a comment