Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Volodymyr Tsap
/
xpdays
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f9f42500
authored
2017-10-29 20:52:41 +0200
by
Volodymyr Tsap
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Adding README.md
1 parent
d18efca8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
15 deletions
README.md
sample5/README.md
sample5/instance.tf
sample5/terraform.tfvars
README.md
0 → 100644
View file @
f9f4250
## XPDays 2017 Building with Terraform code samples
The presentation could be found here:
https://docs.google.com/presentation/d/1ZYWxuzoPwWyzmrM-GJvCnP8DurLZqGRLg-xYMHO4JIw/edit?usp=sharing
### Sample1. Creating Ubuntu instance using one file
1.
Init the Terrarorm
2.
Starting our first instance
3.
Terraform produce the state file
*terraform.tfstate*
### Sample2. Creating ubuntu instance using set of files
1.
AMI selection moved to separate ami.tf
2.
Instance settings parametized by terraform variables
3.
Created variable files:
*terraform.tfvars, variables.tf*
4.
Example for list element selection in
*vpc_security_group_ids*
5.
Example for map element lookup in
*instance_type*
6.
Add metadata variable count
### Sample3. Deploy a sample application, using RDS
1.
Build custom image using packer. Build/redeploy workflow
2.
Deploy a sample application using
*user_data*
3.
Create RDS MySQL database, pass db endpoint to application
4.
Adding outputs
### Sample4. Using funtions and count hints
1.
Moving deployment script into temlplate provider
2.
Using
*length()*
function to get size and create multiple resources
### Sample5. Scaling our applications, adding scaling policies
1.
Add IAM profile for instance
2.
Creating launch configuration, autoscaling grops
3.
Building module
4.
Dealing with LoadBalancers and http
### AppendixA. Upgrading applications environment
1.
Blue/Green deployment
2.
Cannary upgrade
sample5/README.md
View file @
f9f4250
...
...
@@ -4,7 +4,7 @@
2.
Creating launch configuration, autoscaling grops
3.
Building module
4.
Dealing with LoadBalancers and http
5.
Upgrading applications environment
```
# setup your AMS access parameters in ~/.aws
...
...
sample5/instance.tf
View file @
f9f4250
...
...
@@ -9,20 +9,6 @@ data "template_file" "init" {
}
}
# Define the instance
#resource "aws_instance" "xpdays-instance" {
# ami = "${data.aws_ami.xpdays-ami.id}"
# vpc_security_group_ids = [ "${var.vpc_security_group_ids}" ]
# instance_type = "${lookup(var.instance_type, var.environment)}"
# user_data = "${data.template_file.init.*.rendered[count.index]}"
#
# tags {
# Name = "xpdays${count.index + 1}"
# }
#
# count = "${length(var.instance_suffix)}"
#}
resource "aws_launch_configuration" "launch-xpdays" {
# name = "${var.environment}-launch-xpdays${count.index + 1}"
image_id = "${data.aws_ami.xpdays-ami.id}"
...
...
@@ -37,3 +23,28 @@ resource "aws_launch_configuration" "launch-xpdays" {
count = "${length(var.instance_suffix)}"
}
## Add Autoscaling group
resource "aws_autoscaling_group" "asg-xpdays" {
lifecycle { create_before_destroy = true }
# depends_on = ["aws_launch_configuration.launch-xpdays"]
desired_capacity = "${element(var.instance_count_xpdays_desired[var.environment],count.index)}"
max_size = "${lookup(var.instance_count_xpdays_max, var.environment)}"
min_size = "${lookup(var.instance_count_xpdays_min, var.environment)}"
health_check_grace_period = 300
health_check_type = "EC2"
launch_configuration = "${element(aws_launch_configuration.launch-xpdays.*.name, count.index)}"
name = "asg-xpdays${count.index + 1}-${var.environment}"
availability_zones = ["${lookup(var.default_subnet_availability_zone, var.environment)}"]
vpc_zone_identifier = ["${list(aws_subnet.default_subnet.id)}"]
# load_balancers = ["${module.m-elb-xpdays.elb_id}"]
#wait_for_elb_capacity = "${element(var.instance_count_xpdays_desired[var.environment],count.index)}"
# enabled_metrics = "${var.asg_enabled_metrics}"
tag {
key = "Name"
value = "xpdays-${var.instance_suffix[count.index]}-${count.index}"
propagate_at_launch = true
}
count = "${length(var.instance_suffix)}"
}
...
...
sample5/terraform.tfvars
View file @
f9f4250
...
...
@@ -18,3 +18,18 @@ default_db_subnet_group_subnet_ids = {
#
instance_suffix = ["blue","green"]
instance_count_xpdays_desired = {
production = 1
development = 1
}
instance_count_xpdays_min = {
production = 1
development = 1
}
instance_count_xpdays_max = {
production = 3
development = 1
}
...
...
Please
register
or
sign in
to post a comment