Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from HENNGE/lt_version
Browse files Browse the repository at this point in the history
Add option to use the generated LT latest numbered version
  • Loading branch information
michaelaw320 authored Apr 9, 2021
2 parents bb5dace + 2d7c97d commit 2b9f720
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ No requirements.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| asg\_instance\_refresh\_additional\_triggers | Set of additional property names that will trigger an Instance Refresh. A refresh will always be triggered by a change in any of launch\_configuration, launch\_template, or mixed\_instances\_policy. | `list(string)` | `null` | no |
| asg\_instance\_refresh\_healthy\_percentage | The amount of capacity in the Auto Scaling group that must remain healthy during an instance refresh to allow the operation to continue, as a percentage of the desired capacity of the Auto Scaling group. | `number` | `null` | no |
| asg\_instance\_refresh\_strategy | The strategy to use for instance refresh. The only allowed value is `Rolling`. | `string` | `null` | no |
| asg\_instance\_refresh\_warmup | The number of seconds until a newly launched instance is configured and ready to use. | `number` | `null` | no |
| asg\_name | Creates a unique name for autoscaling group beginning with the specified prefix | `string` | `""` | no |
| associate\_public\_ip\_address | Associate a public ip address with an instance in a VPC | `bool` | `false` | no |
| block\_device\_mappings | Mappings of block devices, see https://www.terraform.io/docs/providers/aws/r/launch_template.html#block-devices | `list(any)` | <pre>[<br> {}<br>]</pre> | no |
Expand All @@ -212,7 +216,7 @@ No requirements.
| health\_check\_grace\_period | Time (in seconds) after instance comes into service before checking health | `number` | `300` | no |
| health\_check\_type | Controls how health checking is done. Values are - EC2 and ELB | `string` | n/a | yes |
| iam\_instance\_profile | The IAM instance profile to associate with launched instances | `string` | `""` | no |
| ignore\_desired\_capacity\_changes | Ignores any changes to `desired_count` parameter after apply. Note updating this value will destroy the existing service and recreate it. | `bool` | `false` | no |
| ignore\_desired\_capacity\_changes | Ignores any changes to `desired_capacity` parameter after apply. Note updating this value will destroy the existing service and recreate it. | `bool` | `false` | no |
| image\_id | The EC2 image ID to launch | `string` | `""` | no |
| initial\_lifecycle\_hook\_default\_result | Defines the action the Auto Scaling group should take when the lifecycle hook timeout elapses or if an unexpected failure occurs. The value for this parameter can be either CONTINUE or ABANDON | `string` | `"ABANDON"` | no |
| initial\_lifecycle\_hook\_heartbeat\_timeout | Defines the amount of time, in seconds, that can elapse before the lifecycle hook times out. When the lifecycle hook times out, Auto Scaling performs the action defined in the DefaultResult parameter | `string` | `"60"` | no |
Expand All @@ -226,6 +230,7 @@ No requirements.
| launch\_template | The name of the launch template to use (if it is created outside of this module) | `string` | `""` | no |
| load\_balancers | A list of elastic load balancer names to add to the autoscaling group names | `list(string)` | `[]` | no |
| lt\_name | Creates a unique name for launch template beginning with the specified prefix | `string` | `""` | no |
| lt\_version | Launch Template version to use (if it is created outside of this module). | `string` | `null` | no |
| 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 604800 and 31536000 seconds | `number` | `null` | no |
| max\_size | The maximum size of the auto scale group | `number` | n/a | yes |
| metrics\_granularity | The granularity to associate with the metrics to collect. The only valid value is 1Minute | `string` | `"1Minute"` | no |
Expand All @@ -248,14 +253,11 @@ No requirements.
| tags\_as\_map | A map of tags and values in the same format as other resources accept. This will be converted into the non-standard format that the aws\_autoscaling\_group requires. | `map(any)` | `{}` | no |
| target\_group\_arns | A list of aws\_alb\_target\_group ARNs, for use with Application Load Balancing | `list(string)` | `[]` | no |
| termination\_policies | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are OldestInstance, NewestInstance, OldestLaunchConfiguration, ClosestToNextInstanceHour, Default | `list(string)` | <pre>[<br> "Default"<br>]</pre> | no |
| use\_created\_lt\_latest\_version | Use version number generated by Launch Template instead of $Latest. | `bool` | `false` | no |
| user\_data | The user data to provide when launching the instance | `string` | `" "` | no |
| vpc\_zone\_identifier | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes |
| wait\_for\_capacity\_timeout | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. (See also Waiting for Capacity below.) Setting this to '0' causes Terraform to skip all Capacity Waiting behavior. | `string` | `"10m"` | no |
| wait\_for\_elb\_capacity | Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over min\_elb\_capacity behavior. | `number` | `null` | no |
| asg\_instance\_refresh\_strategy | The strategy to use for instance refresh. The only allowed value is `Rolling`. | `string` | `null` | no |
| asg\_instance\_refresh\_warmup | The number of seconds until a newly launched instance is configured and ready to use. | `number` | `null` | no |
| asg\_instance\_refresh\_healthy\_percentage | The amount of capacity in the Auto Scaling group that must remain healthy during an instance refresh to allow the operation to continue, as a percentage of the desired capacity of the Auto Scaling group. | `number` | `null` | no |
| asg\_instance\_refresh\_additional\_triggers | Set of additional property names that will trigger an Instance Refresh. A refresh will always be triggered by a change in any of launch_configuration, launch_template, or mixed_instances_policy. | `list(string)` | `null` | no |

## Outputs

Expand Down
1 change: 1 addition & 0 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
tags_asg_format = null_resource.tags_as_list_of_maps.*.triggers
lt_version = var.lt_version != null ? var.lt_version : var.use_created_lt_latest_version ? element(concat(aws_launch_template.this.*.latest_version, ["$Latest"]), 0) : "$Latest"
}

resource "null_resource" "tags_as_list_of_maps" {
Expand Down
36 changes: 18 additions & 18 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ resource "aws_autoscaling_group" "this" {
launch_template {
launch_template_specification {
launch_template_id = var.create_lt ? element(concat(aws_launch_template.this.*.id, [""]), 0) : var.launch_template
version = "$Latest"
version = local.lt_version
}

dynamic "override" {
Expand Down Expand Up @@ -151,17 +151,17 @@ resource "aws_autoscaling_group" "this" {
for_each = var.asg_instance_refresh_strategy != null ? [1] : []

content {
strategy = var.asg_instance_refresh_strategy
triggers = var.asg_instance_refresh_additional_triggers
strategy = var.asg_instance_refresh_strategy
triggers = var.asg_instance_refresh_additional_triggers

dynamic "preferences" {
for_each = var.asg_instance_refresh_warmup != null || var.asg_instance_refresh_healthy_percentage != null ? [1] : []
dynamic "preferences" {
for_each = var.asg_instance_refresh_warmup != null || var.asg_instance_refresh_healthy_percentage != null ? [1] : []

content {
instance_warmup = var.asg_instance_refresh_warmup
min_healthy_percentage = var.asg_instance_refresh_healthy_percentage
}
content {
instance_warmup = var.asg_instance_refresh_warmup
min_healthy_percentage = var.asg_instance_refresh_healthy_percentage
}
}
}
}

Expand Down Expand Up @@ -214,7 +214,7 @@ resource "aws_autoscaling_group" "this_ignore_desired_capacity_changes" {
launch_template {
launch_template_specification {
launch_template_id = var.create_lt ? element(concat(aws_launch_template.this.*.id, [""]), 0) : var.launch_template
version = "$Latest"
version = local.lt_version
}

dynamic "override" {
Expand Down Expand Up @@ -264,17 +264,17 @@ resource "aws_autoscaling_group" "this_ignore_desired_capacity_changes" {
for_each = var.asg_instance_refresh_strategy != null ? [1] : []

content {
strategy = var.asg_instance_refresh_strategy
triggers = var.asg_instance_refresh_additional_triggers
strategy = var.asg_instance_refresh_strategy
triggers = var.asg_instance_refresh_additional_triggers

dynamic "preferences" {
for_each = var.asg_instance_refresh_warmup != null || var.asg_instance_refresh_healthy_percentage != null ? [1] : []
dynamic "preferences" {
for_each = var.asg_instance_refresh_warmup != null || var.asg_instance_refresh_healthy_percentage != null ? [1] : []

content {
instance_warmup = var.asg_instance_refresh_warmup
min_healthy_percentage = var.asg_instance_refresh_healthy_percentage
}
content {
instance_warmup = var.asg_instance_refresh_warmup
min_healthy_percentage = var.asg_instance_refresh_healthy_percentage
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ variable "launch_template" {
default = ""
}

variable "lt_version" {
description = "Launch Template version to use (if it is created outside of this module)."
type = string
default = null
}

# Launch template
variable "image_id" {
description = "The EC2 image ID to launch"
Expand Down Expand Up @@ -363,3 +369,9 @@ variable "asg_instance_refresh_additional_triggers" {
type = list(string)
default = null
}

variable "use_created_lt_latest_version" {
description = "Use version number generated by Launch Template instead of $Latest."
default = false
type = bool
}

0 comments on commit 2b9f720

Please sign in to comment.