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
289 stars 553 forks source link

Incorrect Launch template ID refered when Launch template name is changed #182

Closed vishwa-trulioo closed 2 years ago

vishwa-trulioo commented 2 years ago

Description

I am trying to use this module to create an ASG using an already existing launch template. As part of my requirement I want to be able to change the instance template of the ASG. I attempted it it using the below paramters.

  create_launch_template   = false
  launch_template          = "my-template-first"

Then, I changed the value of launch_template to a different launch template. Terraform fails complaining that it can't find the template ID.

Versions

Reproduction

Steps to reproduce the behavior:

Code Snippet to Reproduce

I used the official example with the following as the module code...

module "asg_sg" {
  source  = "terraform-aws-modules/security-group/aws"
  version = "~> 5.1.1"

  name        = "myasg"
  description = "A security group"
  vpc_id      = "sg-xxxxxx"

  create_launch_template   = false
  launch_template          = "my-template-first"

  tags = local.tags
}

Expected behavior

Actual behavior

Generates the following error.

module.asg_sg.aws_autoscaling_group.this[0]: Modifying... [id=myasg]
╷
│ Error: Error updating Auto Scaling Group: ValidationError: Could not find the specified version 10 for the launch template with ID lt-0b8bd84c8f06fa112.
│       status code: 400, request id: 15593a61-1469-47a0-8778-ca01f5702b8c
│ 
│   with module.asg_sg.aws_autoscaling_group.this[0],
│   on .terraform/modules/asg_sg/main.tf line 226, in resource "aws_autoscaling_group" "this":
│  226: resource "aws_autoscaling_group" "this" {
│ 

Terminal Output Screenshot(s)

Additional context

Here is my observation...... When I change the value of the launch_template in the module, Terraform doesn't automatically go an fetch the template ID of new template and use that along with the launch_template name. Instead it uses the old template ID with the new launch_template name. If it is possible to add support to specify the launch template ID and/or launch_template name, then this would be fixed.

bryantbiggs commented 2 years ago

you'll need to add the variable launch_template_version since the template is managed externally from the module

Ref: https://github.com/terraform-aws-modules/terraform-aws-autoscaling/blob/master/main.tf#L235-L239

vishwa-trulioo commented 2 years ago

I used launch_template and launch_template_version both together. Still it gives the same errors. It keeps looking for previous instance template ID. Another note is.... If I recreate it the AG with the new instance template in place, then it works fine. I run in to this issue only when I change the instance template of an existing ASG (without recreating)

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 2 years ago

This issue was automatically closed because of stale in 10 days

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.