f9f42500 by Volodymyr Tsap

Adding README.md

1 parent d18efca8
1 ## XPDays 2017 Building with Terraform code samples
2
3 The presentation could be found here:
4 https://docs.google.com/presentation/d/1ZYWxuzoPwWyzmrM-GJvCnP8DurLZqGRLg-xYMHO4JIw/edit?usp=sharing
5
6 ### Sample1. Creating Ubuntu instance using one file
7
8 1. Init the Terrarorm
9 2. Starting our first instance
10 3. Terraform produce the state file *terraform.tfstate*
11
12 ### Sample2. Creating ubuntu instance using set of files
13
14 1. AMI selection moved to separate ami.tf
15 2. Instance settings parametized by terraform variables
16 3. Created variable files: *terraform.tfvars, variables.tf*
17 4. Example for list element selection in *vpc_security_group_ids*
18 5. Example for map element lookup in *instance_type*
19 6. Add metadata variable count
20
21 ### Sample3. Deploy a sample application, using RDS
22
23 1. Build custom image using packer. Build/redeploy workflow
24 2. Deploy a sample application using *user_data*
25 3. Create RDS MySQL database, pass db endpoint to application
26 4. Adding outputs
27
28 ### Sample4. Using funtions and count hints
29
30 1. Moving deployment script into temlplate provider
31 2. Using *length()* function to get size and create multiple resources
32
33 ### Sample5. Scaling our applications, adding scaling policies
34
35 1. Add IAM profile for instance
36 2. Creating launch configuration, autoscaling grops
37 3. Building module
38 4. Dealing with LoadBalancers and http
39
40 ### AppendixA. Upgrading applications environment
41 1. Blue/Green deployment
42 2. Cannary upgrade
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 2. Creating launch configuration, autoscaling grops 4 2. Creating launch configuration, autoscaling grops
5 3. Building module 5 3. Building module
6 4. Dealing with LoadBalancers and http 6 4. Dealing with LoadBalancers and http
7 7 5. Upgrading applications environment
8 ``` 8 ```
9 # setup your AMS access parameters in ~/.aws 9 # setup your AMS access parameters in ~/.aws
10 10
......
...@@ -9,20 +9,6 @@ data "template_file" "init" { ...@@ -9,20 +9,6 @@ data "template_file" "init" {
9 } 9 }
10 } 10 }
11 11
12 # Define the instance
13 #resource "aws_instance" "xpdays-instance" {
14 # ami = "${data.aws_ami.xpdays-ami.id}"
15 # vpc_security_group_ids = [ "${var.vpc_security_group_ids}" ]
16 # instance_type = "${lookup(var.instance_type, var.environment)}"
17 # user_data = "${data.template_file.init.*.rendered[count.index]}"
18 #
19 # tags {
20 # Name = "xpdays${count.index + 1}"
21 # }
22 #
23 # count = "${length(var.instance_suffix)}"
24 #}
25
26 resource "aws_launch_configuration" "launch-xpdays" { 12 resource "aws_launch_configuration" "launch-xpdays" {
27 # name = "${var.environment}-launch-xpdays${count.index + 1}" 13 # name = "${var.environment}-launch-xpdays${count.index + 1}"
28 image_id = "${data.aws_ami.xpdays-ami.id}" 14 image_id = "${data.aws_ami.xpdays-ami.id}"
...@@ -37,3 +23,28 @@ resource "aws_launch_configuration" "launch-xpdays" { ...@@ -37,3 +23,28 @@ resource "aws_launch_configuration" "launch-xpdays" {
37 count = "${length(var.instance_suffix)}" 23 count = "${length(var.instance_suffix)}"
38 } 24 }
39 25
26 ## Add Autoscaling group
27 resource "aws_autoscaling_group" "asg-xpdays" {
28 lifecycle { create_before_destroy = true }
29 # depends_on = ["aws_launch_configuration.launch-xpdays"]
30 desired_capacity = "${element(var.instance_count_xpdays_desired[var.environment],count.index)}"
31 max_size = "${lookup(var.instance_count_xpdays_max, var.environment)}"
32 min_size = "${lookup(var.instance_count_xpdays_min, var.environment)}"
33 health_check_grace_period = 300
34 health_check_type = "EC2"
35 launch_configuration = "${element(aws_launch_configuration.launch-xpdays.*.name, count.index)}"
36 name = "asg-xpdays${count.index + 1}-${var.environment}"
37 availability_zones = ["${lookup(var.default_subnet_availability_zone, var.environment)}"]
38 vpc_zone_identifier = ["${list(aws_subnet.default_subnet.id)}"]
39 # load_balancers = ["${module.m-elb-xpdays.elb_id}"]
40 #wait_for_elb_capacity = "${element(var.instance_count_xpdays_desired[var.environment],count.index)}"
41 # enabled_metrics = "${var.asg_enabled_metrics}"
42
43 tag {
44 key = "Name"
45 value = "xpdays-${var.instance_suffix[count.index]}-${count.index}"
46 propagate_at_launch = true
47 }
48 count = "${length(var.instance_suffix)}"
49 }
50
......
...@@ -17,4 +17,19 @@ default_db_subnet_group_subnet_ids = { ...@@ -17,4 +17,19 @@ default_db_subnet_group_subnet_ids = {
17 } 17 }
18 18
19 # 19 #
20 instance_suffix = ["blue","green"] 20 instance_suffix = ["blue","green"]
21
22
23 instance_count_xpdays_desired = {
24 production = 1
25 development = 1
26 }
27 instance_count_xpdays_min = {
28 production = 1
29 development = 1
30 }
31 instance_count_xpdays_max = {
32 production = 3
33 development = 1
34 }
35
......