hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.86k stars 9.21k forks source link

Launch Template version update issue in AutoScaling group is not updated on change #25757

Open chaitanyakommoju opened 2 years ago

chaitanyakommoju commented 2 years ago

Community Note

Terraform CLI and Terraform AWS Provider Version

I don't think the terraform version matters, but anyways here are details, I'm using terrafrom version v1.2.4 and AWS provider 4.22.0

$ terraform --version
Terraform v1.2.4
on windows_amd64
+ provider registry.terraform.io/hashicorp/aws v4.22.0
+ provider registry.terraform.io/hashicorp/random v3.3.2

Affected Resource(s)

Terraform Configuration Files

module "app_ec2_asg" {
  source  = "terraform-aws-modules/autoscaling/aws"
  version = "6.3.0"
  # Autoscaling group
  name                      = asg_ec2
  create_launch_template    = true
  min_size                  = 1
  max_size                  = 2
  desired_capacity          = 1
  wait_for_capacity_timeout = 0
  default_cooldown          = 600
  target_group_arns         = module.alb.target_group_arns
  health_check_type         = "EC2"
  vpc_zone_identifier       = module.app_vpc.public_subnets
  security_groups           = [module.app_sg.security_group_id]
  user_data                 = local.ec2_userdata_scripts
  # Launch template
  launch_template_name        = var.ec2_launch_template_name
  launch_template_description = "APP EC2 Launch template "
  update_default_version      = true
  image_id                    = data.aws_ami.amazon_linux_2.id
  instance_type               = var.app_instance_type
  ebs_optimized               = true
  enable_monitoring           = true
  key_name                    = module.ec2_key_pair.key_pair_key_name
  disable_api_termination     = true
  iam_instance_profile_name   = aws_iam_instance_profile.ec2_s3_access_profile.name
  scaling_policies = {
    my-policy = {
      policy_type = "TargetTrackingScaling"
      target_tracking_configuration = {
        predefined_metric_specification = {
          predefined_metric_type = "ASGAverageCPUUtilization"
        }
        target_value = 50.0
      }
    }
  }
  block_device_mappings = [
    {
      # Root volume
      device_name = "/dev/xvda"
      no_device   = 0
      ebs = {
        delete_on_termination = true
        encrypted             = true
        volume_size           = 20
        volume_type           = "gp2"
      }
    }
  ]

  metadata_options = {
    http_endpoint               = "enabled"
    http_tokens                 = "required"
    http_put_response_hop_limit = 5
  }

  tags = {
    vpc_name    = "${var.app_vpc_name}"
    app_name    = "${var.app_name}"
    Environment = "${var.app_environment}"
    Terraform   = "true"
  }

}

Debug Output

╷
│ Error: Provider produced inconsistent final plan
│
│ When expanding the plan for module.app_ec2_asg.aws_autoscaling_group.this[0] to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new     
│ value for .launch_template[0].version: was cty.StringVal("7"), but now cty.StringVal("8").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Panic Output

Expected Behavior

After making any change in the autoscaling group and launching template configuration or in any other resources, it should apply the launch template version to the latest and also should apply the changes

Actual Behavior

After making any change in the autoscaling group and launching template configuration or in any other resources, it should apply the launch template version to the latest and also should apply the changes instead of this, it is throwing the error

╷
│ Error: Provider produced inconsistent final plan
│
│ When expanding the plan for module.app_ec2_asg.aws_autoscaling_group.this[0] to include new values learned so far during apply, provider "registry.terraform.io/hashicorp/aws" produced an invalid new     
│ value for .launch_template[0].version: was cty.StringVal("7"), but now cty.StringVal("8").
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Steps to Reproduce

Use the above terraform configuration provided and with terraform CLI version v1.2.4 and was module versions v4.22.0 and it can be reproduced

  1. terraform apply
  2. confirm the changes with yes

Important Factoids

chaitanyakommoju commented 2 years ago

ewbankkit can you please look into this issue

chaitanyakommoju commented 2 years ago

some can take this and resolve or some one can help out to resolve this issue

BradyShober commented 2 years ago

We are encountering this error as well on v4.23.0 of the provider. In our case, our launch templates we use for our auto scaling groups use custom AMIs. When we publish an updated AMI, we have a process that will automatically update each launch template to use the new AMI. However, the next time we try to apply the Terraform for one of our auto scaling groups after we have published a new AMI, that error is thrown. When it does occur we can just rerun the Terraform and on the second run it will succeed, so while we have that workaround it is not ideal, and will cause some frustration with our application development teams as we begin our rollout of auto scaling within our organization.

jfirebaugh commented 1 year ago

This continues to happen with 5.23.0.