Skip to content

Commit ae09461

Browse files
authored
Refactor - release 2.0 (#25)
* 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
1 parent 6f62338 commit ae09461

File tree

10 files changed

+221
-196
lines changed

10 files changed

+221
-196
lines changed

README.md

+54-53
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# terraform-bluegreen
2+
23
Terraform module to setup blue / green deployments
34

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

89
| Name | Description | Type | Default | Required |
910
|------|-------------|:----:|:-----:|:-----:|
10-
| associate\_public\_ip\_address | (Optional) Associate a public ip address with an instance in a VPC | string | `"false"` | no |
11-
| blue\_ami | (Required) The EC2 image ID to launch in the blue autoscaling group | string | n/a | yes |
12-
| blue\_desired\_capacity | (Required) The number of Amazon EC2 instances that should be running in the blue autoscaling roup | string | n/a | yes |
13-
| blue\_max\_size | (Required) The maximum size of the blue autoscaling group | string | n/a | yes |
14-
| blue\_min\_size | (Required) The minimum size of the blue autoscaling group | string | n/a | yes |
15-
| disk\_volume\_size | (Optional) The size of the volume in gigabytes | string | `"8"` | no |
16-
| disk\_volume\_type | (Optional) The type of the volume. Default is standard | string | `"standard"` | no |
17-
| environment | Environment to deploy on | string | n/a | yes |
18-
| green\_ami | (Required) The EC2 image ID to launch in the green autoscaling group | string | n/a | yes |
19-
| green\_desired\_capacity | (Required) The number of Amazon EC2 instances that should be running in the green autoscaling roup | string | n/a | yes |
20-
| green\_max\_size | (Required) The maximum size of the green autoscaling group | string | n/a | yes |
21-
| green\_min\_size | (Required) The minimum size of the green autoscaling group | string | n/a | yes |
22-
| health\_check\_grace\_period | (Optional, Default: 300) Time (in seconds) after instance comes into service before checking health | string | `"300"` | no |
11+
| associate\_public\_ip\_address | Associate a public ip address with an instance in a VPC | string | `"false"` | no |
12+
| blue\_ami | The EC2 image ID to launch in the Blue autoscaling group | string | n/a | yes |
13+
| blue\_desired\_capacity | The number of Amazon EC2 instances that should be running in the blue autoscaling roup | string | n/a | yes |
14+
| blue\_disk\_volume\_size | The size of the EBS volume in GB for the Blue instances | string | `"8"` | no |
15+
| blue\_disk\_volume\_type | The EBS volume type for the Blue instances | string | `"gp2"` | no |
16+
| blue\_instance\_type | The Blue instance type to launch | string | n/a | yes |
17+
| blue\_max\_size | The maximum size of the blue autoscaling group | string | n/a | yes |
18+
| blue\_min\_size | The minimum size of the blue autoscaling group | string | n/a | yes |
19+
| blue\_user\_data | The user data to provide when launching the Blue instances | string | `"# Hello World"` | no |
20+
| green\_ami | The EC2 image ID to launch in the Green autoscaling group | string | n/a | yes |
21+
| green\_desired\_capacity | The number of Amazon EC2 instances that should be running in the green autoscaling roup | string | n/a | yes |
22+
| green\_disk\_volume\_size | The size of the EBS volume in GB for the Green instances | string | `"8"` | no |
23+
| green\_disk\_volume\_type | The EBS volume type for the Green instances | string | `"gp2"` | no |
24+
| green\_instance\_type | The Green instance type to launch | string | n/a | yes |
25+
| green\_max\_size | The maximum size of the green autoscaling group | string | n/a | yes |
26+
| green\_min\_size | The minimum size of the green autoscaling group | string | n/a | yes |
27+
| green\_user\_data | The user data to provide when launching the Green instances | string | `"# Hello World"` | no |
28+
| health\_check\_grace\_period | Time (in seconds) after instance comes into service before checking health | string | `"300"` | no |
2329
| health\_check\_type | The health check type to apply to the Autoscaling groups. | string | `"ELB"` | no |
24-
| iam\_instance\_profile | (Optional) The IAM instance profile to associate with launched instances | string | `""` | no |
25-
| instance\_type | (Required) The size of instance to launch | string | n/a | yes |
26-
| key\_name | (Optional) The key name that should be used for the instance | string | `""` | no |
27-
| loadbalancers | (Optional) A list of load balancer names to add to the autoscaling groups | list | `<list>` | no |
28-
| name | Name of the stack | string | n/a | yes |
29-
| project | Project name to use | string | n/a | yes |
30-
| security\_groups | (Optional) A list of associated security group IDS | list | `<list>` | no |
30+
| iam\_instance\_profile | The IAM instance profile to associate with launched instances | string | `""` | no |
31+
| 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 |
32+
| key\_name | The key name that should be used for the instance | string | `""` | no |
33+
| loadbalancers | A list of load balancer names to add to the autoscaling groups | list | `<list>` | no |
34+
| name | Name of the Auto Scaling Groups | string | n/a | yes |
35+
| security\_groups | A list of associated security group IDS | list | `<list>` | no |
3136
| 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 |
32-
| subnets | (Optional) A list of subnet IDs to launch resources in | list | `<list>` | no |
33-
| tags | (Optional, Default: []) List of map of additional tags | list | `<list>` | no |
37+
| subnets | A list of subnet IDs to launch resources in | list | `<list>` | no |
38+
| tags | List as a map of additional tags | list | `<list>` | no |
3439
| target\_group\_arns | A list of aws_alb_target_group ARNs, for use with Application Load Balancing | list | `<list>` | no |
35-
| termination\_policies | (Optional, Default: ['Default']) Order in termination policies to apply when choosing instances to terminate. | list | `<list>` | no |
36-
| user\_data | (Optional) The user data to provide when launching the instance | string | `"# Hello World"` | no |
40+
| termination\_policies | Order in termination policies to apply when choosing instances to terminate. | list | `<list>` | no |
3741
| 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 |
3842

3943
### Outputs
@@ -42,26 +46,27 @@ Terraform module to setup blue / green deployments
4246
|------|-------------|
4347
| blue\_asg\_id | Blue autoscaling group id |
4448
| green\_asg\_id | Green autoscaling group id |
49+
| nonbinding\_blue\_asg\_name | This is the raw blue autoscaling group name, without creating a dependency with the actual autoscaling group resource |
50+
| nonbinding\_green\_asg\_name | This is the raw green autoscaling group name, without creating a dependency with the actual autoscaling group resource |
4551

4652
### Example
4753

4854
```terraform
4955
module "bluegreen" {
50-
source = "github.com/skyscrapers/terraform-bluegreen//blue-green"
51-
project = "example"
52-
name = "app"
53-
environment = "production"
54-
blue_ami = "ami-blabla"
55-
green_ami = "ami-blabla"
56-
instance_type = "t2.micro"
57-
loadbalancers = []
58-
blue_max_size = "5"
59-
blue_min_size = "2"
60-
blue_desired_capacity = "2"
61-
green_max_size = "0"
62-
green_min_size = "0"
63-
green_desired_capacity = "0"
64-
security_groups = []
56+
source = "github.com/skyscrapers/terraform-bluegreen//blue-green"
57+
name = "app-${terraform.workspace}"
58+
blue_ami = "ami-blabla"
59+
blue_instance_type = "t3.micro"
60+
blue_max_size = 5
61+
blue_min_size = 2
62+
blue_desired_capacity = 2
63+
green_ami = "ami-blabla"
64+
green_instance_type = "t3.micro"
65+
green_max_size = 0
66+
green_min_size = 0
67+
green_desired_capacity = 0
68+
loadbalancers = ["myloadbalancers"]
69+
security_groups = ["mysecuritygroups"]
6570
}
6671
```
6772

@@ -76,21 +81,19 @@ Terraform module to setup alarms and autoscaling triggers for autoscaling
7681
| adjustment\_down | The number of instances to remove when the alarm is triggered (the value has to be negative) | string | `"-1"` | no |
7782
| adjustment\_type | What typ of adjustment needs to happen | string | `"ChangeInCapacity"` | no |
7883
| adjustment\_up | The number of instances to add when the alarm is triggered | string | `"1"` | no |
79-
| autoscaling\_group\_name | The name of the AS group this config needs to be applied | list | n/a | yes |
84+
| autoscaling\_group\_names | The names of the Auto Scaling Groups this config needs to be applied to | list | n/a | yes |
8085
| cooldown\_down | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | string | `"600"` | no |
8186
| cooldown\_up | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start. | string | `"300"` | no |
8287
| dimension\_name | | string | `"AutoScalingGroupName"` | no |
8388
| dimension\_value | | string | `"false"` | no |
84-
| environment | Environment to deploy on | string | n/a | yes |
85-
| evaluation\_periods | the number of samples to evaluate | string | `"4"` | no |
89+
| evaluation\_periods | The number of samples to evaluate | string | `"4"` | no |
8690
| metric\_name | The metric the scaling is based upon | string | `"CPUUtilization"` | no |
87-
| name | Name of the stack | string | n/a | yes |
88-
| namespace | the namespace of the cloudwatch metric | string | `"AWS/EC2"` | no |
89-
| num\_asg | the number of autoscaling groups passed | string | `"2"` | no |
90-
| period\_down | he period in seconds over which the selected metric statistic is applied. | string | `"120"` | no |
91-
| period\_up | he period in seconds over which the selected metric statistic is applied. | string | `"60"` | no |
91+
| name | Name of the Auto Scaling Groups | string | n/a | yes |
92+
| namespace | The namespace of the cloudwatch metric | string | `"AWS/EC2"` | no |
93+
| num\_asg | The number of autoscaling groups passed | string | `"2"` | no |
94+
| period\_down | The period in seconds over which the selected metric statistic is applied. | string | `"120"` | no |
95+
| period\_up | The period in seconds over which the selected metric statistic is applied. | string | `"60"` | no |
9296
| policy\_type | The policy type, either SimpleScaling or StepScaling | string | `"SimpleScaling"` | no |
93-
| project | Project name to use | string | n/a | yes |
9497
| statistic | The statistic to apply to the alarm's associated metric. Either of the following is supported: | string | `"Average"` | no |
9598
| threshold\_down | The metric value to scale down | string | `"30"` | no |
9699
| threshold\_up | The metric value to scale up | string | `"80"` | no |
@@ -99,11 +102,9 @@ Terraform module to setup alarms and autoscaling triggers for autoscaling
99102

100103
```terraform
101104
module "scaling" {
102-
source = "github.com/skyscrapers/terraform-bluegreen//scaling"
103-
project = "example"
104-
name = "app"
105-
environment = "production"
106-
autoscaling_group_name = ["my_asg_name1","my_asg_name2"]
105+
source = "github.com/skyscrapers/terraform-bluegreen//scaling"
106+
name = "app-${terraform.workspace}"
107+
autoscaling_group_names = ["my_asg_name1","my_asg_name2"]
107108
}
108109
```
109110

blue-green/main.tf

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
11
module "blue" {
22
source = "../single-stack"
33
color = "blue"
4+
name = "${var.name}"
45
max_size = "${var.blue_max_size}"
56
min_size = "${var.blue_min_size}"
67
desired_capacity = "${var.blue_desired_capacity}"
78
ami = "${var.blue_ami}"
9+
user_data = "${var.blue_user_data}"
10+
instance_type = "${var.blue_instance_type}"
11+
disk_volume_size = "${var.blue_disk_volume_size}"
12+
disk_volume_type = "${var.blue_disk_volume_type}"
813
spot_price = "${var.spot_price}"
9-
loadbalancers = "${var.loadbalancers}"
10-
project = "${var.project}"
11-
name = "${var.name}"
12-
environment = "${var.environment}"
13-
instance_type = "${var.instance_type}"
14+
loadbalancers = ["${var.loadbalancers}"]
1415
key_name = "${var.key_name}"
15-
security_groups = "${var.security_groups}"
16+
security_groups = ["${var.security_groups}"]
1617
iam_instance_profile = "${var.iam_instance_profile}"
1718
associate_public_ip_address = "${var.associate_public_ip_address}"
18-
user_data = "${var.user_data}"
19-
disk_volume_size = "${var.disk_volume_size}"
20-
disk_volume_type = "${var.disk_volume_type}"
2119
subnets = "${var.subnets}"
2220
health_check_grace_period = "${var.health_check_grace_period}"
2321
termination_policies = ["${var.termination_policies}"]
24-
target_group_arns = "${var.target_group_arns}"
22+
target_group_arns = ["${var.target_group_arns}"]
2523
health_check_type = "${var.health_check_type}"
26-
tags = "${var.tags}"
2724
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
25+
tags = "${var.tags}"
26+
initial_lifecycle_hooks = ["${var.initial_lifecycle_hooks}"]
2827
}
2928

3029
module "green" {
3130
source = "../single-stack"
3231
color = "green"
32+
name = "${var.name}"
3333
max_size = "${var.green_max_size}"
3434
min_size = "${var.green_min_size}"
3535
desired_capacity = "${var.green_desired_capacity}"
3636
ami = "${var.green_ami}"
37+
user_data = "${var.green_user_data}"
38+
instance_type = "${var.green_instance_type}"
39+
disk_volume_size = "${var.green_disk_volume_size}"
40+
disk_volume_type = "${var.green_disk_volume_type}"
3741
spot_price = "${var.spot_price}"
38-
loadbalancers = "${var.loadbalancers}"
39-
project = "${var.project}"
40-
name = "${var.name}"
41-
environment = "${var.environment}"
42-
instance_type = "${var.instance_type}"
42+
loadbalancers = ["${var.loadbalancers}"]
4343
key_name = "${var.key_name}"
44-
security_groups = "${var.security_groups}"
44+
security_groups = ["${var.security_groups}"]
4545
iam_instance_profile = "${var.iam_instance_profile}"
4646
associate_public_ip_address = "${var.associate_public_ip_address}"
47-
user_data = "${var.user_data}"
48-
disk_volume_size = "${var.disk_volume_size}"
49-
disk_volume_type = "${var.disk_volume_type}"
5047
subnets = "${var.subnets}"
5148
health_check_grace_period = "${var.health_check_grace_period}"
5249
termination_policies = ["${var.termination_policies}"]
53-
target_group_arns = "${var.target_group_arns}"
50+
target_group_arns = ["${var.target_group_arns}"]
5451
health_check_type = "${var.health_check_type}"
55-
tags = "${var.tags}"
5652
wait_for_capacity_timeout = "${var.wait_for_capacity_timeout}"
53+
tags = "${var.tags}"
54+
initial_lifecycle_hooks = ["${var.initial_lifecycle_hooks}"]
5755
}

blue-green/outputs.tf

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
output "blue_asg_id" {
22
description = "Blue autoscaling group id"
3-
value = "${module.blue.asg_id}"
3+
value = "${module.blue.asg_id}"
44
}
55

66
output "green_asg_id" {
77
description = "Green autoscaling group id"
8-
value = "${module.green.asg_id}"
8+
value = "${module.green.asg_id}"
9+
}
10+
11+
output "nonbinding_blue_asg_name" {
12+
description = "This is the raw blue autoscaling group name, without creating a dependency with the actual autoscaling group resource"
13+
value = "${module.blue.nonbinding_asg_name}"
14+
}
15+
16+
output "nonbinding_green_asg_name" {
17+
description = "This is the raw green autoscaling group name, without creating a dependency with the actual autoscaling group resource"
18+
value = "${module.green.nonbinding_asg_name}"
919
}

0 commit comments

Comments
 (0)