Skip to content

Commit

Permalink
Allow multiple traffic source attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Yethal committed Jun 25, 2024
1 parent e562239 commit abb907a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ 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_attachment"></a> [create\_traffic\_source\_attachment](#input\_create\_traffic\_source\_attachment) | Determines whether to create autoscaling group traffic source attachment | `bool` | `false` | 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 @@ -348,8 +348,7 @@ No modules.
| <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_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 |
| <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 |
| <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_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
10 changes: 7 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ module "complete" {
service_linked_role_arn = aws_iam_service_linked_role.autoscaling.arn

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

initial_lifecycle_hooks = [
{
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,13 @@ resource "aws_autoscaling_group" "idc" {
################################################################################

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

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

traffic_source {
identifier = var.traffic_source_identifier
type = var.traffic_source_type
identifier = each.value.traffic_source_identifier
type = each.value.traffic_source_type
}
}

Expand Down
18 changes: 6 additions & 12 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -472,22 +472,16 @@ variable "tag_specifications" {
# Autoscaling group traffic source attachment
################################################################################

variable "create_traffic_source_attachment" {
description = "Determines whether to create 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_identifier" {
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"
type = string
default = ""
}

variable "traffic_source_type" {
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"
type = string
default = "elbv2"
variable "traffic_source_attachments" {
description = "Map of traffic source attachments to create"
type = map(any)
default = {}
}

################################################################################
Expand Down

0 comments on commit abb907a

Please sign in to comment.