Skip to content

Commit

Permalink
feat: Complete remaining breaking changes and add upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantbiggs committed Aug 13, 2024
1 parent 09e1861 commit d85fba6
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.88.0
rev: v1.92.1
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand All @@ -24,7 +24,7 @@ repos:
- '--args=--only=terraform_unused_required_providers'
- id: terraform_validate
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Note: the default behavior of the module is to create an autoscaling group and l

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

## Providers
Expand Down Expand Up @@ -274,7 +274,6 @@ No modules.
| <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 |
| <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 |
| <a name="input_create_schedule"></a> [create\_schedule](#input\_create\_schedule) | Determines whether to create autoscaling group schedule or not | `bool` | `true` | no |
| <a name="input_create_traffic_source_attachments"></a> [create\_traffic\_source\_attachments](#input\_create\_traffic\_source\_attachments) | Determines whether to create autoscaling group traffic source attachments | `bool` | `false` | no |
| <a name="input_credit_specification"></a> [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instance | `map(string)` | `{}` | no |
| <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 |
| <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 |
Expand Down Expand Up @@ -322,7 +321,6 @@ No modules.
| <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 |
| <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 |
| <a name="input_license_specifications"></a> [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `{}` | no |
| <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 |
| <a name="input_maintenance_options"></a> [maintenance\_options](#input\_maintenance\_options) | The maintenance options for the instance | `any` | `{}` | no |
| <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 |
| <a name="input_max_size"></a> [max\_size](#input\_max\_size) | The maximum size of the autoscaling group | `number` | `null` | no |
Expand All @@ -346,9 +344,8 @@ No modules.
| <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 |
| <a name="input_tag_specifications"></a> [tag\_specifications](#input\_tag\_specifications) | The tags to apply to the resources during launch | `list(any)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to assign to resources | `map(string)` | `{}` | no |
| <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 |
| <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 |
| <a name="input_traffic_source_attachments"></a> [traffic\_source\_attachments](#input\_traffic\_source\_attachments) | Map of traffic source attachments to create | `map(any)` | `{}` | no |
| <a name="input_traffic_source_attachments"></a> [traffic\_source\_attachments](#input\_traffic\_source\_attachments) | Map of traffic source attachment definitions to create | `any` | `{}` | no |
| <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 |
| <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 |
| <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 |
Expand Down
96 changes: 96 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Upgrade from v7.x to v8.x

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:
If you find a bug, please open an issue with supporting configuration to reproduce.

## List of backwards incompatible changes

- `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
- Users can now create multiple `traffic_source_attachments` instead of previously where the module only supported one attachment
- The minimum supported version of Terraform has been raised to `v1.3`

## Additional changes

### Added

- None

### Modified

- None

### Variable and output changes

1. Removed variables:

- `load_balancers`
- `target_group_arns`
- `create_traffic_source_attachment`
- `traffic_source_identifier`
- `traffic_source_type`

2. Renamed variables:

- None

3. Added variables:

- `traffic_source_attachments`

4. Removed outputs:

- `launch_configuration_id`
- `launch_configuration_arn`
- `launch_configuration_name`

5. Renamed outputs:

- None

6. Added outputs:

- None

## Upgrade Migrations

### Before 7.x Example

```hcl
module "asg" {
source = "terraform-aws-modules/autoscaling/aws"
version = "~> 7.0"
# Truncated for brevity
# Traffic source attachment
create_traffic_source_attachment = true
traffic_source_identifier = "arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456"
traffic_source_type = "elbv2"
...
}
```

### After 8.x Example

```hcl
module "asg" {
source = "terraform-aws-modules/autoscaling/aws"
version = "~> 8.0"
# Truncated for brevity
traffic_source_attachments = {
ex-alb = {
traffic_source_identifier = "arn:aws:elasticloadbalancing:us-east-2:123456789012:loadbalancer/app/my-load-balancer/1234567890123456"
traffic_source_type = "elbv2"
}
...
}
...
}
```

### State Changes

There are no required state changes to migrate from `v7.x` to `v8.x`.
2 changes: 1 addition & 1 deletion examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Note that this example may create resources which cost money. Run `terraform des

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

## Providers
Expand Down
5 changes: 2 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ module "complete" {
service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn

# Traffic source attachment
create_traffic_source_attachments = true
traffic_source_attachments = {
asg = {
ex-alb = {
traffic_source_identifier = module.alb.target_groups["ex_asg"].arn
traffic_source_type = "elbv2"
traffic_source_type = "elbv2" # default
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.0"
required_version = ">= 1.3"

required_providers {
aws = {
Expand Down
16 changes: 8 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,9 @@ resource "aws_autoscaling_group" "this" {
default_instance_warmup = var.default_instance_warmup
protect_from_scale_in = var.protect_from_scale_in

# TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
load_balancers = var.load_balancers
# TODO - remove at next breaking change. Use `traffic_source_identifier`/`traffic_source_type` instead
target_group_arns = var.target_group_arns
# Use `traffic_source_identifier`/`traffic_source_type` instead
# load_balancers = var.load_balancers
# target_group_arns = var.target_group_arns
placement_group = var.placement_group
health_check_type = var.health_check_type
health_check_grace_period = var.health_check_grace_period
Expand Down Expand Up @@ -666,8 +665,9 @@ resource "aws_autoscaling_group" "idc" {
default_instance_warmup = var.default_instance_warmup
protect_from_scale_in = var.protect_from_scale_in

load_balancers = var.load_balancers
target_group_arns = var.target_group_arns
# Use `traffic_source_identifier`/`traffic_source_type` instead
# load_balancers = var.load_balancers
# target_group_arns = var.target_group_arns
placement_group = var.placement_group
health_check_type = var.health_check_type
health_check_grace_period = var.health_check_grace_period
Expand Down Expand Up @@ -928,13 +928,13 @@ resource "aws_autoscaling_group" "idc" {
################################################################################

resource "aws_autoscaling_traffic_source_attachment" "this" {
for_each = { for k, v in var.traffic_source_attachments : k => v if local.create && var.create_traffic_source_attachments }
for_each = { for k, v in var.traffic_source_attachments : k => v if local.create }

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

traffic_source {
identifier = each.value.traffic_source_identifier
type = each.value.traffic_source_type
type = try(each.value.traffic_source_type, "elbv2")
}
}

Expand Down
22 changes: 2 additions & 20 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,6 @@ variable "protect_from_scale_in" {
default = false
}

variable "load_balancers" {
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"
type = list(string)
default = []
}

variable "target_group_arns" {
description = "A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing"
type = list(string)
default = []
}

variable "placement_group" {
description = "The name of the placement group into which you'll launch your instances, if any"
type = string
Expand Down Expand Up @@ -472,15 +460,9 @@ variable "tag_specifications" {
# Autoscaling group traffic source attachment
################################################################################

variable "create_traffic_source_attachments" {
description = "Determines whether to create autoscaling group traffic source attachments"
type = bool
default = false
}

variable "traffic_source_attachments" {
description = "Map of traffic source attachments to create"
type = map(any)
description = "Map of traffic source attachment definitions to create"
type = any
default = {}
}

Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 1.0"
required_version = ">= 1.3"

required_providers {
aws = {
Expand Down

0 comments on commit d85fba6

Please sign in to comment.