Skip to content

Commit

Permalink
Refactor - release 2.0 (#25)
Browse files Browse the repository at this point in the history
* Complete refactor - release 2.0

* Update description

* 2.0.1 (#26)

* Return the autoscaling group names without creating a dependency (test)

* Add initial lifecycle hooks variable

* Documentation

* Revert bluegreen.py changes

* Process feedback
  • Loading branch information
duboisph committed Apr 29, 2019
1 parent 6f62338 commit ae09461
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 196 deletions.
107 changes: 54 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# terraform-bluegreen

Terraform module to setup blue / green deployments

## blue-green
Expand All @@ -7,33 +8,36 @@ Terraform module to setup blue / green deployments

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| associate\_public\_ip\_address | (Optional) Associate a public ip address with an instance in a VPC | string | `"false"` | no |
| blue\_ami | (Required) The EC2 image ID to launch in the blue autoscaling group | string | n/a | yes |
| blue\_desired\_capacity | (Required) The number of Amazon EC2 instances that should be running in the blue autoscaling roup | string | n/a | yes |
| blue\_max\_size | (Required) The maximum size of the blue autoscaling group | string | n/a | yes |
| blue\_min\_size | (Required) The minimum size of the blue autoscaling group | string | n/a | yes |
| disk\_volume\_size | (Optional) The size of the volume in gigabytes | string | `"8"` | no |
| disk\_volume\_type | (Optional) The type of the volume. Default is standard | string | `"standard"` | no |
| environment | Environment to deploy on | string | n/a | yes |
| green\_ami | (Required) The EC2 image ID to launch in the green autoscaling group | string | n/a | yes |
| green\_desired\_capacity | (Required) The number of Amazon EC2 instances that should be running in the green autoscaling roup | string | n/a | yes |
| green\_max\_size | (Required) The maximum size of the green autoscaling group | string | n/a | yes |
| green\_min\_size | (Required) The minimum size of the green autoscaling group | string | n/a | yes |
| health\_check\_grace\_period | (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health | string | `"300"` | no |
| associate\_public\_ip\_address | Associate a public ip address with an instance in a VPC | string | `"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 | string | n/a | yes |
| blue\_disk\_volume\_size | The size of the EBS volume in GB for the Blue instances | string | `"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 | string | n/a | yes |
| blue\_min\_size | The minimum size of the blue autoscaling group | string | 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 | string | n/a | yes |
| green\_disk\_volume\_size | The size of the EBS volume in GB for the Green instances | string | `"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 | string | n/a | yes |
| green\_min\_size | The minimum size of the green autoscaling group | string | 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 | string | `"300"` | no |
| health\_check\_type | The health check type to apply to the Autoscaling groups. | string | `"ELB"` | no |
| iam\_instance\_profile | (Optional) The IAM instance profile to associate with launched instances | string | `""` | no |
| instance\_type | (Required) The size of instance to launch | string | n/a | yes |
| key\_name | (Optional) The key name that should be used for the instance | string | `""` | no |
| loadbalancers | (Optional) A list of load balancer names to add to the autoscaling groups | list | `<list>` | no |
| name | Name of the stack | string | n/a | yes |
| project | Project name to use | string | n/a | yes |
| security\_groups | (Optional) A list of associated security group IDS | list | `<list>` | no |
| iam\_instance\_profile | The IAM instance profile to associate with launched instances | string | `""` | no |
| initial\_lifecycle\_hooks | One or more [Lifecycle Hooks](http://docs.aws.amazon.com/autoscaling/latest/userguide/lifecycle-hooks.html) to attach to the autoscaling group before instances are launched. The syntax is exactly the same as the separate [`aws_autoscaling_lifecycle_hook`](https://www.terraform.io/docs/providers/aws/r/autoscaling_lifecycle_hooks.html) resource, without the autoscaling_group_name attribute | list | `<list>` | no |
| key\_name | The key name that should be used for the instance | string | `""` | no |
| loadbalancers | A list of load balancer names to add to the autoscaling groups | list | `<list>` | no |
| name | Name of the Auto Scaling Groups | string | n/a | yes |
| security\_groups | A list of associated security group IDS | list | `<list>` | 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 | (Optional) A list of subnet IDs to launch resources in | list | `<list>` | no |
| tags | (Optional, Default: []) List of map of additional tags | list | `<list>` | no |
| subnets | A list of subnet IDs to launch resources in | list | `<list>` | no |
| tags | List as a map of additional tags | list | `<list>` | no |
| target\_group\_arns | A list of aws_alb_target_group ARNs, for use with Application Load Balancing | list | `<list>` | no |
| termination\_policies | (Optional, Default: ['Default']) Order in termination policies to apply when choosing instances to terminate. | list | `<list>` | no |
| user\_data | (Optional) The user data to provide when launching the instance | string | `"# Hello World"` | no |
| termination\_policies | Order in termination policies to apply when choosing instances to terminate. | list | `<list>` | 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
Expand All @@ -42,26 +46,27 @@ Terraform module to setup blue / green deployments
|------|-------------|
| 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

```terraform
module "bluegreen" {
source = "github.com/skyscrapers/terraform-bluegreen//blue-green"
project = "example"
name = "app"
environment = "production"
blue_ami = "ami-blabla"
green_ami = "ami-blabla"
instance_type = "t2.micro"
loadbalancers = []
blue_max_size = "5"
blue_min_size = "2"
blue_desired_capacity = "2"
green_max_size = "0"
green_min_size = "0"
green_desired_capacity = "0"
security_groups = []
source = "github.com/skyscrapers/terraform-bluegreen//blue-green"
name = "app-${terraform.workspace}"
blue_ami = "ami-blabla"
blue_instance_type = "t3.micro"
blue_max_size = 5
blue_min_size = 2
blue_desired_capacity = 2
green_ami = "ami-blabla"
green_instance_type = "t3.micro"
green_max_size = 0
green_min_size = 0
green_desired_capacity = 0
loadbalancers = ["myloadbalancers"]
security_groups = ["mysecuritygroups"]
}
```

Expand All @@ -76,21 +81,19 @@ Terraform module to setup alarms and autoscaling triggers for autoscaling
| adjustment\_down | The number of instances to remove when the alarm is triggered (the value has to be negative) | string | `"-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 | string | `"1"` | no |
| autoscaling\_group\_name | The name of the AS group this config needs to be applied | list | n/a | yes |
| autoscaling\_group\_names | The names of the Auto Scaling Groups this config needs to be applied to | list | n/a | yes |
| cooldown\_down | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | string | `"600"` | no |
| cooldown\_up | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | string | `"300"` | no |
| dimension\_name | | string | `"AutoScalingGroupName"` | no |
| dimension\_value | | string | `"false"` | no |
| environment | Environment to deploy on | string | n/a | yes |
| evaluation\_periods | the number of samples to evaluate | string | `"4"` | no |
| evaluation\_periods | The number of samples to evaluate | string | `"4"` | no |
| metric\_name | The metric the scaling is based upon | string | `"CPUUtilization"` | no |
| name | Name of the stack | string | n/a | yes |
| namespace | the namespace of the cloudwatch metric | string | `"AWS/EC2"` | no |
| num\_asg | the number of autoscaling groups passed | string | `"2"` | no |
| period\_down | he period in seconds over which the selected metric statistic is applied. | string | `"120"` | no |
| period\_up | he period in seconds over which the selected metric statistic is applied. | string | `"60"` | no |
| name | Name of the Auto Scaling Groups | string | n/a | yes |
| namespace | The namespace of the cloudwatch metric | string | `"AWS/EC2"` | no |
| num\_asg | The number of autoscaling groups passed | string | `"2"` | no |
| period\_down | The period in seconds over which the selected metric statistic is applied. | string | `"120"` | no |
| period\_up | The period in seconds over which the selected metric statistic is applied. | string | `"60"` | no |
| policy\_type | The policy type, either SimpleScaling or StepScaling | string | `"SimpleScaling"` | no |
| project | Project name to use | string | n/a | yes |
| 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 | string | `"30"` | no |
| threshold\_up | The metric value to scale up | string | `"80"` | no |
Expand All @@ -99,11 +102,9 @@ Terraform module to setup alarms and autoscaling triggers for autoscaling

```terraform
module "scaling" {
source = "github.com/skyscrapers/terraform-bluegreen//scaling"
project = "example"
name = "app"
environment = "production"
autoscaling_group_name = ["my_asg_name1","my_asg_name2"]
source = "github.com/skyscrapers/terraform-bluegreen//scaling"
name = "app-${terraform.workspace}"
autoscaling_group_names = ["my_asg_name1","my_asg_name2"]
}
```

Expand Down
42 changes: 20 additions & 22 deletions blue-green/main.tf
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
module "blue" {
source = "../single-stack"
color = "blue"
name = "${var.name}"
max_size = "${var.blue_max_size}"
min_size = "${var.blue_min_size}"
desired_capacity = "${var.blue_desired_capacity}"
ami = "${var.blue_ami}"
user_data = "${var.blue_user_data}"
instance_type = "${var.blue_instance_type}"
disk_volume_size = "${var.blue_disk_volume_size}"
disk_volume_type = "${var.blue_disk_volume_type}"
spot_price = "${var.spot_price}"
loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
loadbalancers = ["${var.loadbalancers}"]
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
security_groups = ["${var.security_groups}"]
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
target_group_arns = ["${var.target_group_arns}"]
health_check_type = "${var.health_check_type}"
tags = "${var.tags}"
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
tags = "${var.tags}"
initial_lifecycle_hooks = ["${var.initial_lifecycle_hooks}"]
}

module "green" {
source = "../single-stack"
color = "green"
name = "${var.name}"
max_size = "${var.green_max_size}"
min_size = "${var.green_min_size}"
desired_capacity = "${var.green_desired_capacity}"
ami = "${var.green_ami}"
user_data = "${var.green_user_data}"
instance_type = "${var.green_instance_type}"
disk_volume_size = "${var.green_disk_volume_size}"
disk_volume_type = "${var.green_disk_volume_type}"
spot_price = "${var.spot_price}"
loadbalancers = "${var.loadbalancers}"
project = "${var.project}"
name = "${var.name}"
environment = "${var.environment}"
instance_type = "${var.instance_type}"
loadbalancers = ["${var.loadbalancers}"]
key_name = "${var.key_name}"
security_groups = "${var.security_groups}"
security_groups = ["${var.security_groups}"]
iam_instance_profile = "${var.iam_instance_profile}"
associate_public_ip_address = "${var.associate_public_ip_address}"
user_data = "${var.user_data}"
disk_volume_size = "${var.disk_volume_size}"
disk_volume_type = "${var.disk_volume_type}"
subnets = "${var.subnets}"
health_check_grace_period = "${var.health_check_grace_period}"
termination_policies = ["${var.termination_policies}"]
target_group_arns = "${var.target_group_arns}"
target_group_arns = ["${var.target_group_arns}"]
health_check_type = "${var.health_check_type}"
tags = "${var.tags}"
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
tags = "${var.tags}"
initial_lifecycle_hooks = ["${var.initial_lifecycle_hooks}"]
}
14 changes: 12 additions & 2 deletions blue-green/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
output "blue_asg_id" {
description = "Blue autoscaling group id"
value = "${module.blue.asg_id}"
value = "${module.blue.asg_id}"
}

output "green_asg_id" {
description = "Green autoscaling group id"
value = "${module.green.asg_id}"
value = "${module.green.asg_id}"
}

output "nonbinding_blue_asg_name" {
description = "This is the raw blue autoscaling group name, without creating a dependency with the actual autoscaling group resource"
value = "${module.blue.nonbinding_asg_name}"
}

output "nonbinding_green_asg_name" {
description = "This is the raw green autoscaling group name, without creating a dependency with the actual autoscaling group resource"
value = "${module.green.nonbinding_asg_name}"
}
Loading

0 comments on commit ae09461

Please sign in to comment.