Skip to content

Commit abd6265

Browse files
release of target_group create_before_destroy to allow target_group changes in flight (#59)
1 parent 833b297 commit abd6265

File tree

8 files changed

+61
-12
lines changed

8 files changed

+61
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
66
project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [v3.2.0] - 2018-03-28
9+
10+
### Changed
11+
12+
* `create_before_destroy` lifecycle policy added to the target groups. This allows target groups to be modified, though means they're recreated anytime they're changed. A change MUST include a change to the `name` value or will fail on duplicates. (nice work, @egarbi 🦄)
13+
814
## [v3.1.0] - 2018-03-22
915

1016
### Added

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ Balancer (ALB) running over HTTP/HTTPS. Available through the [terraform registr
1616

1717
The module supports both (mutually exclusive):
1818

19-
* Internal IP ALBs
20-
* External IP ALBs
19+
* Internal ALBs
20+
* External ALBs
2121

2222
It's recommended you use this module with [terraform-aws-vpc](https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws),
2323
[terraform-aws-security-group](https://registry.terraform.io/modules/terraform-aws-modules/security-group/aws), and
2424
[terraform-aws-autoscaling](https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws/).
2525

26+
Note:
27+
28+
It's strongly recommended that the autoscaling module is instantiated in the same
29+
state as the ALB module as in flight changes to active target groups need to be propagated
30+
to the ASG immediately or will result in failure. The value of `target_group[n][name]` also must change any time there are modifications to existing `target_groups`.
31+
2632
## Why ALB instead of ELB
2733

2834
The use-case presented here appears almost identical to how one would use an ELB
@@ -43,17 +49,17 @@ A full example leveraging other community modules is contained in the [examples/
4349
module "alb" {
4450
source = "terraform-aws-modules/alb/aws"
4551
load_balancer_name = "my-alb"
46-
load_balancer_security_groups = ["sg-edcd9784", "sg-edcd9785"]
52+
security_groups = ["sg-edcd9784", "sg-edcd9785"]
4753
log_bucket_name = "logs-us-east-2-123456789012"
4854
log_location_prefix = "my-alb-logs"
4955
subnets = ["subnet-abcde012", subnet-bcde012a"]
5056
tags = "${map("Environment", "test")}"
5157
vpc_id = "vpc-abcde012"
5258
https_listeners = "${list(map("certificate_arn", "arn:aws:iam::123456789012:server-certificate/test_cert-123456789012", "port", 443))}"
5359
https_listeners_count = "1"
54-
target_groups = "${list(map("name", "foo", "backend_protocol", "HTTP", "backend_port", "80"))}"
55-
http_tcp_listeners_count = "1"
5660
http_tcp_listeners = "${list(map("port", "80", "protocol", "HTTP"))}"
61+
http_tcp_listeners_count = "1"
62+
target_groups = "${list(map("name", "foo", "backend_protocol", "HTTP", "backend_port", "80"))}"
5763
target_groups_count = "1"
5864
}
5965
```

examples/alb_test_fixture/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ The following IAM policy is the minimum needed to execute the module from the te
1717
"Sid": "Stmt1507789535000",
1818
"Effect": "Allow",
1919
"Action": [
20+
"autoscaling:*LoadBalancerTargetGroups",
21+
"autoscaling:*AutoScalingGroup",
22+
"autoscaling:*LaunchConfiguration",
23+
"autoscaling:*AutoScalingGroups",
24+
"autoscaling:*LaunchConfigurations",
2025
"ec2:AllocateAddress",
2126
"ec2:AssignIpv6Addresses",
2227
"ec2:AssignPrivateIpAddresses",

examples/alb_test_fixture/data.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ data "aws_iam_policy_document" "bucket_policy" {
1818
}
1919
}
2020
}
21+
22+
data "aws_ami" "ubuntu" {
23+
most_recent = true
24+
25+
filter {
26+
name = "name"
27+
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
28+
}
29+
30+
filter {
31+
name = "virtualization-type"
32+
values = ["hvm"]
33+
}
34+
35+
owners = ["099720109477"] # Canonical
36+
}

examples/alb_test_fixture/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ module "security_group" {
6565
tags = "${local.tags}"
6666
}
6767

68+
resource "aws_autoscaling_group" "test" {
69+
name_prefix = "test-alb"
70+
max_size = 1
71+
min_size = 1
72+
launch_configuration = "${aws_launch_configuration.as_conf.name}"
73+
health_check_type = "EC2"
74+
target_group_arns = ["${module.alb.target_group_arns}"]
75+
force_delete = true
76+
vpc_zone_identifier = ["${module.vpc.public_subnets}"]
77+
}
78+
79+
resource "aws_launch_configuration" "as_conf" {
80+
name = "web_config"
81+
image_id = "${data.aws_ami.ubuntu.id}"
82+
instance_type = "t2.micro"
83+
}
84+
6885
module "alb" {
6986
source = "../.."
7087
load_balancer_name = "test-alb-${random_string.suffix.result}"

main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ resource "aws_lb_target_group" "main" {
4848
enabled = "${lookup(var.target_groups[count.index], "stickiness_enabled", lookup(var.target_groups_defaults, "stickiness_enabled"))}"
4949
}
5050

51-
tags = "${merge(var.tags, map("Name", lookup(var.target_groups[count.index], "name")))}"
52-
count = "${var.target_groups_count}"
53-
51+
tags = "${merge(var.tags, map("Name", lookup(var.target_groups[count.index], "name")))}"
52+
count = "${var.target_groups_count}"
5453
depends_on = ["aws_lb.application"]
5554

5655
lifecycle {

outputs.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ output "http_tcp_listener_ids" {
1414
}
1515

1616
output "https_listener_arns" {
17-
description = "The ARN of the HTTPS load balancer listeners created."
17+
description = "The ARNs of the HTTPS load balancer listeners created."
1818
value = "${slice(concat(aws_lb_listener.frontend_https.*.arn, list("")), 0, var.https_listeners_count)}"
1919
}
2020

2121
output "https_listener_ids" {
22-
description = "The ID of the load balancer listeners created."
22+
description = "The IDs of the load balancer listeners created."
2323
value = "${slice(concat(aws_lb_listener.frontend_https.*.id, list("")), 0, var.https_listeners_count)}"
2424
}
2525

@@ -39,7 +39,7 @@ output "load_balancer_zone_id" {
3939
}
4040

4141
output "target_group_arns" {
42-
description = "ARN of the target group. Useful for passing to your Auto Scaling group module."
42+
description = "ARNs of the target groups. Useful for passing to your Auto Scaling group."
4343
value = "${slice(concat(aws_lb_target_group.main.*.arn, list("")), 0, var.target_groups_count)}"
4444
}
4545

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.1.0
1+
v3.2.0

0 commit comments

Comments
 (0)