Skip to content

Commit 3782413

Browse files
Yethalbryantbiggs
andauthored
feat!: Allow multiple traffic source attachments (#273)
* Allow multiple traffic source attachments * feat: Complete remaining breaking changes and add upgrade guide --------- Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
1 parent 4e32cf2 commit 3782413

File tree

9 files changed

+122
-51
lines changed

9 files changed

+122
-51
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.88.0
3+
rev: v1.92.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
@@ -24,7 +24,7 @@ repos:
2424
- '--args=--only=terraform_unused_required_providers'
2525
- id: terraform_validate
2626
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.5.0
27+
rev: v4.6.0
2828
hooks:
2929
- id: check-merge-conflict
3030
- id: end-of-file-fixer

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Note: the default behavior of the module is to create an autoscaling group and l
230230

231231
| Name | Version |
232232
|------|---------|
233-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
233+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
234234
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.55 |
235235

236236
## Providers
@@ -274,7 +274,6 @@ No modules.
274274
| <a name="input_create_launch_template"></a> [create\_launch\_template](#input\_create\_launch\_template) | Determines whether to create launch template or not | `bool` | `true` | no |
275275
| <a name="input_create_scaling_policy"></a> [create\_scaling\_policy](#input\_create\_scaling\_policy) | Determines whether to create target scaling policy schedule or not | `bool` | `true` | no |
276276
| <a name="input_create_schedule"></a> [create\_schedule](#input\_create\_schedule) | Determines whether to create autoscaling group schedule or not | `bool` | `true` | no |
277-
| <a name="input_create_traffic_source_attachment"></a> [create\_traffic\_source\_attachment](#input\_create\_traffic\_source\_attachment) | Determines whether to create autoscaling group traffic source attachment | `bool` | `false` | no |
278277
| <a name="input_credit_specification"></a> [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instance | `map(string)` | `{}` | no |
279278
| <a name="input_default_cooldown"></a> [default\_cooldown](#input\_default\_cooldown) | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start | `number` | `null` | no |
280279
| <a name="input_default_instance_warmup"></a> [default\_instance\_warmup](#input\_default\_instance\_warmup) | Amount of time, in seconds, until a newly launched instance can contribute to the Amazon CloudWatch metrics. This delay lets an instance finish initializing before Amazon EC2 Auto Scaling aggregates instance metrics, resulting in more reliable usage data. Set this value equal to the amount of time that it takes for resource consumption to become stable after an instance reaches the InService state. | `number` | `null` | no |
@@ -322,7 +321,6 @@ No modules.
322321
| <a name="input_launch_template_use_name_prefix"></a> [launch\_template\_use\_name\_prefix](#input\_launch\_template\_use\_name\_prefix) | Determines whether to use `launch_template_name` as is or create a unique name beginning with the `launch_template_name` as the prefix | `bool` | `true` | no |
323322
| <a name="input_launch_template_version"></a> [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no |
324323
| <a name="input_license_specifications"></a> [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `{}` | no |
325-
| <a name="input_load_balancers"></a> [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no |
326324
| <a name="input_maintenance_options"></a> [maintenance\_options](#input\_maintenance\_options) | The maintenance options for the instance | `any` | `{}` | no |
327325
| <a name="input_max_instance_lifetime"></a> [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 86400 and 31536000 seconds | `number` | `null` | no |
328326
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | The maximum size of the autoscaling group | `number` | `null` | no |
@@ -346,10 +344,8 @@ No modules.
346344
| <a name="input_suspended_processes"></a> [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the Auto Scaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`, `InstanceRefresh`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your Auto Scaling Group from functioning properly | `list(string)` | `[]` | no |
347345
| <a name="input_tag_specifications"></a> [tag\_specifications](#input\_tag\_specifications) | The tags to apply to the resources during launch | `list(any)` | `[]` | no |
348346
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to resources | `map(string)` | `{}` | no |
349-
| <a name="input_target_group_arns"></a> [target\_group\_arns](#input\_target\_group\_arns) | A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing | `list(string)` | `[]` | no |
350347
| <a name="input_termination_policies"></a> [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the Auto Scaling Group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default` | `list(string)` | `[]` | no |
351-
| <a name="input_traffic_source_identifier"></a> [traffic\_source\_identifier](#input\_traffic\_source\_identifier) | Identifies the traffic source. For Application Load Balancers, Gateway Load Balancers, Network Load Balancers, and VPC Lattice, this will be the Amazon Resource Name (ARN) for a target group in this account and Region. For Classic Load Balancers, this will be the name of the Classic Load Balancer in this account and Region | `string` | `""` | no |
352-
| <a name="input_traffic_source_type"></a> [traffic\_source\_type](#input\_traffic\_source\_type) | Provides additional context for the value of identifier. The following lists the valid values: `elb` if `identifier` is the name of a Classic Load Balancer. `elbv2` if `identifier` is the ARN of an Application Load Balancer, Gateway Load Balancer, or Network Load Balancer target group. `vpc-lattice` if `identifier` is the ARN of a VPC Lattice target group | `string` | `"elbv2"` | no |
348+
| <a name="input_traffic_source_attachments"></a> [traffic\_source\_attachments](#input\_traffic\_source\_attachments) | Map of traffic source attachment definitions to create | `any` | `{}` | no |
353349
| <a name="input_update_default_version"></a> [update\_default\_version](#input\_update\_default\_version) | Whether to update Default Version each update. Conflicts with `default_version` | `bool` | `null` | no |
354350
| <a name="input_use_mixed_instances_policy"></a> [use\_mixed\_instances\_policy](#input\_use\_mixed\_instances\_policy) | Determines whether to use a mixed instances policy in the autoscaling group or not | `bool` | `false` | no |
355351
| <a name="input_use_name_prefix"></a> [use\_name\_prefix](#input\_use\_name\_prefix) | Determines whether to use `name` as is or create a unique name beginning with the `name` as the prefix | `bool` | `true` | no |

UPGRADE-8.0.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Upgrade from v7.x to v8.x
2+
3+
If you have any questions regarding this upgrade process, please consult the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-autoscaling/tree/master/examples/complete) directory:
4+
If you find a bug, please open an issue with supporting configuration to reproduce.
5+
6+
## List of backwards incompatible changes
7+
8+
- `target_group_arns` and `load_balancers` are no longer supported on the ASG; instead users should use the `traffic_source_attachments` which cover this functionality and more
9+
- Users can now create multiple `traffic_source_attachments` instead of previously where the module only supported one attachment
10+
- The minimum supported version of Terraform has been raised to `v1.3`
11+
12+
## Additional changes
13+
14+
### Added
15+
16+
- None
17+
18+
### Modified
19+
20+
- None
21+
22+
### Variable and output changes
23+
24+
1. Removed variables:
25+
26+
- `load_balancers`
27+
- `target_group_arns`
28+
- `create_traffic_source_attachment`
29+
- `traffic_source_identifier`
30+
- `traffic_source_type`
31+
32+
2. Renamed variables:
33+
34+
- None
35+
36+
3. Added variables:
37+
38+
- `traffic_source_attachments`
39+
40+
4. Removed outputs:
41+
42+
- `launch_configuration_id`
43+
- `launch_configuration_arn`
44+
- `launch_configuration_name`
45+
46+
5. Renamed outputs:
47+
48+
- None
49+
50+
6. Added outputs:
51+
52+
- None
53+
54+
## Upgrade Migrations
55+
56+
### Before 7.x Example
57+
58+
```hcl
59+
module "asg" {
60+
source = "terraform-aws-modules/autoscaling/aws"
61+
version = "~> 7.0"
62+
63+
# Truncated for brevity
64+
65+
# Traffic source attachment
66+
create_traffic_source_attachment = true
67+
traffic_source_identifier = "arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456"
68+
traffic_source_type = "elbv2"
69+
70+
...
71+
}
72+
```
73+
74+
### After 8.x Example
75+
76+
```hcl
77+
module "asg" {
78+
source = "terraform-aws-modules/autoscaling/aws"
79+
version = "~> 8.0"
80+
81+
# Truncated for brevity
82+
83+
traffic_source_attachments = {
84+
ex-alb = {
85+
traffic_source_identifier = "arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456"
86+
traffic_source_type = "elbv2"
87+
}
88+
...
89+
}
90+
...
91+
}
92+
```
93+
94+
### State Changes
95+
96+
There are no required state changes to migrate from `v7.x` to `v8.x`.

examples/complete/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Note that this example may create resources which cost money. Run `terraform des
2929

3030
| Name | Version |
3131
|------|---------|
32-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
32+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
3333
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.55 |
3434

3535
## Providers

examples/complete/main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ module "complete" {
4747
service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn
4848

4949
# Traffic source attachment
50-
create_traffic_source_attachment = true
51-
traffic_source_identifier = module.alb.target_groups["ex_asg"].arn
52-
traffic_source_type = "elbv2"
50+
traffic_source_attachments = {
51+
ex-alb = {
52+
traffic_source_identifier = module.alb.target_groups["ex_asg"].arn
53+
traffic_source_type = "elbv2" # default
54+
}
55+
}
5356

5457
initial_lifecycle_hooks = [
5558
{

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3"
33

44
required_providers {
55
aws = {

main.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,9 @@ resource "aws_autoscaling_group" "this" {
374374
default_instance_warmup = var.default_instance_warmup
375375
protect_from_scale_in = var.protect_from_scale_in
376376

377-
# TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
378-
load_balancers = var.load_balancers
379-
# TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
380-
target_group_arns = var.target_group_arns
377+
# Use `traffic_source_identifier`/`traffic_source_type` instead
378+
# load_balancers = var.load_balancers
379+
# target_group_arns = var.target_group_arns
381380
placement_group = var.placement_group
382381
health_check_type = var.health_check_type
383382
health_check_grace_period = var.health_check_grace_period
@@ -666,8 +665,9 @@ resource "aws_autoscaling_group" "idc" {
666665
default_instance_warmup = var.default_instance_warmup
667666
protect_from_scale_in = var.protect_from_scale_in
668667

669-
load_balancers = var.load_balancers
670-
target_group_arns = var.target_group_arns
668+
# Use `traffic_source_identifier`/`traffic_source_type` instead
669+
# load_balancers = var.load_balancers
670+
# target_group_arns = var.target_group_arns
671671
placement_group = var.placement_group
672672
health_check_type = var.health_check_type
673673
health_check_grace_period = var.health_check_grace_period
@@ -928,13 +928,13 @@ resource "aws_autoscaling_group" "idc" {
928928
################################################################################
929929

930930
resource "aws_autoscaling_traffic_source_attachment" "this" {
931-
count = local.create && var.create_traffic_source_attachment ? 1 : 0
931+
for_each = { for k, v in var.traffic_source_attachments : k => v if local.create }
932932

933933
autoscaling_group_name = var.ignore_desired_capacity_changes ? aws_autoscaling_group.idc[0].id : aws_autoscaling_group.this[0].id
934934

935935
traffic_source {
936-
identifier = var.traffic_source_identifier
937-
type = var.traffic_source_type
936+
identifier = each.value.traffic_source_identifier
937+
type = try(each.value.traffic_source_type, "elbv2")
938938
}
939939
}
940940

variables.tf

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,6 @@ variable "protect_from_scale_in" {
121121
default = false
122122
}
123123

124-
variable "load_balancers" {
125-
description = "A list of elastic load balancer names to add to the autoscaling group names. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead"
126-
type = list(string)
127-
default = []
128-
}
129-
130-
variable "target_group_arns" {
131-
description = "A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing"
132-
type = list(string)
133-
default = []
134-
}
135-
136124
variable "placement_group" {
137125
description = "The name of the placement group into which you'll launch your instances, if any"
138126
type = string
@@ -472,22 +460,10 @@ variable "tag_specifications" {
472460
# Autoscaling group traffic source attachment
473461
################################################################################
474462

475-
variable "create_traffic_source_attachment" {
476-
description = "Determines whether to create autoscaling group traffic source attachment"
477-
type = bool
478-
default = false
479-
}
480-
481-
variable "traffic_source_identifier" {
482-
description = "Identifies the traffic source. For Application Load Balancers, Gateway Load Balancers, Network Load Balancers, and VPC Lattice, this will be the Amazon Resource Name (ARN) for a target group in this account and Region. For Classic Load Balancers, this will be the name of the Classic Load Balancer in this account and Region"
483-
type = string
484-
default = ""
485-
}
486-
487-
variable "traffic_source_type" {
488-
description = "Provides additional context for the value of identifier. The following lists the valid values: `elb` if `identifier` is the name of a Classic Load Balancer. `elbv2` if `identifier` is the ARN of an Application Load Balancer, Gateway Load Balancer, or Network Load Balancer target group. `vpc-lattice` if `identifier` is the ARN of a VPC Lattice target group"
489-
type = string
490-
default = "elbv2"
463+
variable "traffic_source_attachments" {
464+
description = "Map of traffic source attachment definitions to create"
465+
type = any
466+
default = {}
491467
}
492468

493469
################################################################################

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 1.0"
2+
required_version = ">= 1.3"
33

44
required_providers {
55
aws = {

0 commit comments

Comments
 (0)