项目作者: skyscrapers

项目描述 :
Terraform module to setup blue / green deployments
高级语言: HCL
项目地址: git://github.com/skyscrapers/terraform-bluegreen.git
创建时间: 2016-11-08T16:56:05Z
项目社区:https://github.com/skyscrapers/terraform-bluegreen

开源协议:MIT License

下载


terraform-bluegreen

Terraform module to setup blue / green deployments

blue-green

Inputs

Name Description Type Default Required
associate_public_ip_address Associate a public ip address with an instance in a VPC bool false no
blue_ami The EC2 image ID to launch in the Blue autoscaling group string n/a yes
blue_desired_capacity The number of Amazon EC2 instances that should be running in the blue autoscaling roup number n/a yes
blue_disk_volume_size The size of the EBS volume in GB for the Blue instances number 8 no
blue_disk_volume_type The EBS volume type for the Blue instances string "gp2" no
blue_instance_type The Blue instance type to launch string n/a yes
blue_max_size The maximum size of the blue autoscaling group number n/a yes
blue_min_size The minimum size of the blue autoscaling group number n/a yes
blue_user_data The user data to provide when launching the Blue instances string "# Hello World" no
green_ami The EC2 image ID to launch in the Green autoscaling group string n/a yes
green_desired_capacity The number of Amazon EC2 instances that should be running in the green autoscaling roup number n/a yes
green_disk_volume_size The size of the EBS volume in GB for the Green instances number 8 no
green_disk_volume_type The EBS volume type for the Green instances string "gp2" no
green_instance_type The Green instance type to launch string n/a yes
green_max_size The maximum size of the green autoscaling group number n/a yes
green_min_size The minimum size of the green autoscaling group number n/a yes
green_user_data The user data to provide when launching the Green instances string "# Hello World" no
health_check_grace_period Time (in seconds) after instance comes into service before checking health number 300 no
health_check_type The health check type to apply to the Autoscaling groups. string "ELB" no
iam_instance_profile The IAM instance profile to associate with launched instances string null no
initial_lifecycle_hooks One or more Lifecycle Hooks to attach to the autoscaling group before instances are launched. The syntax is exactly the same as the separate aws_autoscaling_lifecycle_hook resource, without the autoscaling_group_name attribute list(map(string)) [] no
key_name The key name that should be used for the instance string null no
loadbalancers A list of load balancer names to add to the autoscaling groups list(string) [] no
name Name of the Auto Scaling Groups string n/a yes
security_groups A list of associated security group IDS list(string) [] no
spot_price Spot price you want to pay for your instances. By default this is empty and we will use on-demand instances string "" no
subnets A list of subnet IDs to launch resources in list(string) [] no
tags List as a map of additional tags list(map(string)) [] no
target_group_arns A list of aws_alb_target_group ARNs, for use with Application Load Balancing list(string) [] no
termination_policies Order in termination policies to apply when choosing instances to terminate. list(string) [] no
wait_for_capacity_timeout A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to 0 causes Terraform to skip all Capacity Waiting behavior. string "10m" no

Outputs

Name Description
blue_asg_id Blue autoscaling group id
green_asg_id Green autoscaling group id
nonbinding_blue_asg_name This is the raw blue autoscaling group name, without creating a dependency with the actual autoscaling group resource
nonbinding_green_asg_name This is the raw green autoscaling group name, without creating a dependency with the actual autoscaling group resource

Example

  1. module "bluegreen" {
  2. source = "github.com/skyscrapers/terraform-bluegreen//blue-green"
  3. name = "app-${terraform.workspace}"
  4. blue_ami = "ami-blabla"
  5. blue_instance_type = "t3.micro"
  6. blue_max_size = 5
  7. blue_min_size = 2
  8. blue_desired_capacity = 2
  9. green_ami = "ami-blabla"
  10. green_instance_type = "t3.micro"
  11. green_max_size = 0
  12. green_min_size = 0
  13. green_desired_capacity = 0
  14. loadbalancers = ["myloadbalancers"]
  15. security_groups = ["mysecuritygroups"]
  16. }

scaling

Terraform module to setup alarms and autoscaling triggers for autoscaling

Inputs

Name Description Type Default Required
adjustment_down The number of instances to remove when the alarm is triggered (the value has to be negative) number -1 no
adjustment_type What typ of adjustment needs to happen string "ChangeInCapacity" no
adjustment_up The number of instances to add when the alarm is triggered number 1 no
autoscaling_group_names The names of the Auto Scaling Groups this config needs to be applied to list(string) n/a yes
cooldown_down The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. number 600 no
cooldown_up The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. number 300 no
datapoints_to_alarm_down The number of datapoints that must be breaching to trigger the scale DOWN alarm number n/a yes
datapoints_to_alarm_up The number of datapoints that must be breaching to trigger the scale UP alarm number n/a yes
dimension_name n/a string "AutoScalingGroupName" no
dimension_value n/a string n/a yes
evaluation_periods The number of samples to evaluate number 4 no
metric_name The metric the scaling is based upon string "CPUUtilization" no
name Name for the created resources string n/a yes
namespace The namespace of the cloudwatch metric string "AWS/EC2" no
num_asg The number of autoscaling groups passed number 2 no
period_down The period in seconds over which the selected metric statistic is applied. number 120 no
period_up The period in seconds over which the selected metric statistic is applied. number 60 no
policy_type The policy type, either SimpleScaling or StepScaling string "SimpleScaling" no
statistic The statistic to apply to the alarm’s associated metric. Either of the following is supported: string "Average" no
threshold_down The metric value to scale down number 30 no
threshold_up The metric value to scale up number 80 no

Example

  1. module "scaling" {
  2. source = "github.com/skyscrapers/terraform-bluegreen//scaling"
  3. name = "app-${terraform.workspace}"
  4. autoscaling_group_names = ["my_asg_name1","my_asg_name2"]
  5. }

Blue-green deployments

The bluegreen.py script performs a bluegreen deployment of the selected terraform stack. It only works with Python 2.7.
The blue-green deployment script expects certain inputs and outputs in the Terraform project you want to deploy in a blue-green fashion.

Required outputs

  1. output "blue_asg_id" {
  2. value = "${module.<blue-green-module-name>.blue_asg_id}"
  3. }
  4. output "green_asg_id" {
  5. value = "${module.<blue-green-module-name>.green_asg_id}"
  6. }

Required variables

  1. variable "blue_max_size" {
  2. description = "max instances blue"
  3. }
  4. variable "blue_min_size" {
  5. description = "min instances blue"
  6. }
  7. variable "blue_desired_capacity" {
  8. description = "desired instances blue"
  9. }
  10. variable "green_max_size" {
  11. description = "max instances green"
  12. }
  13. variable "green_min_size" {
  14. description = "min instances green"
  15. }
  16. variable "green_desired_capacity" {
  17. description = "desired instances green"
  18. }
  19. variable "blue_ami" {
  20. description = "blue ami"
  21. }
  22. variable "green_ami" {
  23. description = "green ami"
  24. }

These input variables need to be assigned to your module. Make sure you do a terraform refresh to be sure that the terraform outputs are saved in the Terraform state file.

Usage

First you need to install the requirements:

  1. pip install -r requirements.txt

Run ./bluegreen.py --help to see the available options.

Example:

  1. ./bluegreen.py -f stacks/test/application -a ami-xxxx -c apply -t 500