terraform-aws-modules / terraform-aws-autoscaling

Terraform module to create AWS Auto Scaling resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/autoscaling/aws
Apache License 2.0
292 stars 556 forks source link

Instance Refresh not working #155

Closed bhardister closed 3 years ago

bhardister commented 3 years ago

Description

I attempted half a dozen times to have the autoscaling group instance refresh automatically start when I applied a plan that made a change to the launch template. It never did.

Versions

Reproduction

Specifically, with 2 active instances and a min_healthy_percentage of 50%, my understanding is that if I applied a change to the instance type, the ASG would automatically kick off an instance refresh replacing one then the other instance with instances using the new instance type.

Code Snippet to Reproduce

Here's my module spec: module "autoscaling" { source = "terraform-aws-modules/autoscaling/aws" version = "4.1.0" create_asg = true name = local.name_prefix min_size = var.min_size max_size = var.max_size desired_capacity = var.desired_capacity wait_for_elb_capacity = var.desired_capacity wait_for_capacity_timeout = var.wait_for_capacity_timeout health_check_type = var.health_check_type health_check_grace_period = var.health_check_grace_period enabled_metrics = var.enabled_metrics

vpc_zone_identifier = var.vpc_zone_identifier initial_lifecycle_hooks = [ { name = "LaunchLifeCycleHook" default_result = "ABANDON" heartbeat_timeout = var.launch_lc_hook_timeout lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING" notification_metadata = jsonencode({ "deployments" = "completed" }) }, { name = "TerminationLifeCycleHook" default_result = "ABANDON" heartbeat_timeout = var.terminate_lc_hook_timeout lifecycle_transition = "autoscaling:EC2_INSTANCE_TERMINATING" notification_metadata = jsonencode({ "octo-deploy-target" = "deleted" }) } ] instance_refresh = { strategy = "Rolling" preferences = { min_healthy_percentage = 50 } }

use_lt = true create_lt = true

lt_name = local.name_prefix lt_use_name_prefix = true description = "ss-web launch template" update_default_version = true

image_id = var.image_id instance_type = var.instance_type ebs_optimized = true enable_monitoring = var.enable_monitoring

iam_instance_profile_name = var.iam_instance_profile key_name = var.key_name security_groups = var.security_groups service_linked_role_arn = var.service_linked_role_arn target_group_arns = var.target_group_arns user_data_base64 = filebase64("${path.module}/userdata.ps1")
hibernation_options = { configured = false }

block_device_mappings = [ { device_name = "/dev/xvda" no_device = 1 ebs = { delete_on_termination = true encrypted = var.encrypted volume_size = var.data_volume_size_d volume_type = "gp2" } } ]

tags = [ { key = "Name" value = local.name_prefix propagate_at_launch = true }, { key = "TargetEnvironment" value = var.target_environment propagate_at_launch = true }, { key = "TargetTenant" value = var.tenant propagate_at_launch = true }, { key = "Group" value = "infrastructure" propagate_at_launch = true }, { key = "NewRelicAlert" value = var.new_relic_alert_level propagate_at_launch = true }, { key = "PartitionLetter" value = upper(var.tenant) propagate_at_launch = true }, { key = "Patch Group" value = var.patch_group propagate_at_launch = true }, { key = "ServerEnvironment" value = var.server_environment propagate_at_launch = true }, { key = "ServerType" value = var.server_type propagate_at_launch = true }, ] }

bhardister commented 3 years ago

Needed to add lt_version = $Latest

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.