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.61k stars 9k forks source link

[Bug]: AWS terraform provider does not recognize changes for autoscale_group #36532

Open EugenKon opened 3 months ago

EugenKon commented 3 months ago

Terraform Core Version

1.7.4

AWS Provider Version

4.67.0

Affected Resource(s)

Expected Behavior

terraform should notice both changes.

Actual Behavior

terraform plan notices only one change: image

Where I did two changes: image

I suppose this happened because for worker-autoscale group current version is equal to latest version: image

But please note even if it is numerically equal to latest, but it is not the same as $Latest. Look at the plan with $Latest value:

resource "aws_autoscaling_group" "worker" {
  name                      = "worker-autoscale"
  desired_capacity          = 2
  ...
  launch_template {
    id      = aws_launch_template.worker.id
    version = "$Latest"
  }
$ terraform plan -target aws_autoscaling_group.worker -out wg
...
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_autoscaling_group.worker will be updated in-place
  ~ resource "aws_autoscaling_group" "worker" {
      ~ desired_capacity          = 3 -> 2
        id                        = "worker-autoscale"
        name                      = "worker-autoscale"
        # (24 unchanged attributes hidden)

      - timeouts {}

        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

I expect to see from the output above next change: version = "3" -> "$Latest"

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

described above. It looks like this part should be logically upper.

Steps to Reproduce

described above

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

EugenKon commented 3 months ago

And, possibly this is a different bug, but I can not apply changes only to one resource. TF suggest to change 4 resources, instead of just one requested!

terraform plan -target aws_autoscaling_group.www -out wg1
data.aws_iam_policy_document.ec2-assume-role-policy: Reading...
aws_vpc.prd_plntr: Refreshing state... [id=vpc-***]
data.aws_iam_policy_document.ec2-assume-role-policy: Read complete after 0s [id=***]
aws_iam_role.www: Refreshing state... [id=www-***]
aws_iam_instance_profile.www: Refreshing state... [id=www-***]
aws_security_group.internal_traffic: Refreshing state... [id=sg-***]
aws_security_group.ssh_for_all: Refreshing state... [id=sg-***]
aws_lb_target_group.www-https: Refreshing state... [id=arn:a***]
aws_lb_target_group.www-http: Refreshing state... [id=arn:a***]
aws_subnet.b_prd_plntr: Refreshing state... [id=subnet-***]
aws_security_group.all_egress: Refreshing state... [id=sg-**]
aws_security_group.www: Refreshing state... [id=sg-**]
aws_lb_target_group.www-https-autoscale: Refreshing state... [id=ar***]
aws_security_group.etcd: Refreshing state... [id=sg-**]
aws_launch_template.www: Refreshing state... [id=lt-***]
aws_autoscaling_group.www: Refreshing state... [id=www-autoscale]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_autoscaling_group.www will be updated in-place
  ~ resource "aws_autoscaling_group" "www" {
        id                        = "www-autoscale"
        name                      = "www-autoscale"
        # (25 unchanged attributes hidden)

      ~ launch_template {
            id      = "lt-***"
            name    = "www-autoscale"
          ~ version = "$Latest" -> "4"
        }

        # (3 unchanged blocks hidden)
    }

  # aws_lb_target_group.www-http will be updated in-place
  ~ resource "aws_lb_target_group" "www-http" {
        id                                 = "****"
        name                               = "www-http"
        tags                               = {}
        # (16 unchanged attributes hidden)

      ~ health_check {
          ~ matcher             = "200-299" -> "200-399"
            # (8 unchanged attributes hidden)
        }

        # (2 unchanged blocks hidden)
    }

  # aws_lb_target_group.www-https will be updated in-place
  ~ resource "aws_lb_target_group" "www-https" {
        id                                 = "arn:aws:***"
        name                               = "www-https"
        tags                               = {}
        # (16 unchanged attributes hidden)

      ~ health_check {
          ~ matcher             = "200-299" -> "200-399"
            # (8 unchanged attributes hidden)
        }

      ~ stickiness {
          ~ cookie_duration = 10 -> 300
            # (2 unchanged attributes hidden)
        }

        # (1 unchanged block hidden)
    }

  # aws_lb_target_group.www-https-autoscale will be updated in-place
  ~ resource "aws_lb_target_group" "www-https-autoscale" {
      + connection_termination             = false
        id                                 = "arn:aws:****:us-east-1:***"
      + lambda_multi_value_headers_enabled = false
        name                               = "www-https-autoscale"
      + proxy_protocol_v2                  = false
        tags                               = {}
        # (13 unchanged attributes hidden)

      ~ health_check {
          ~ matcher             = "200-299" -> "200"
            # (8 unchanged attributes hidden)
        }

      ~ stickiness {
          ~ cookie_duration = 10 -> 86400
          ~ enabled         = true -> false
            # (1 unchanged attribute hidden)
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 4 to change, 0 to destroy.
╷
│ Warning: Resource targeting is in effect
│
│ You are creating a plan with the -target option, which means that the result of this plan may not represent
│ all of the changes requested by the current configuration.
│
│ The -target option is not for routine use, and is provided only for exceptional situations such as recovering
│ from errors or mistakes, or when Terraform specifically suggests to use it as part of an error message.
╵