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.66k stars 9.03k forks source link

aws_autoscaling_lifecycle_hook does not properly delete notification_metadata #21329

Closed gurchik closed 1 week ago

gurchik commented 2 years ago

Terraform Version

terraform version
Terraform v1.0.8
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v3.62.0

Terraform Configuration Files

resource "aws_autoscaling_lifecycle_hook" "test" {
  name                   = "redacted"
  autoscaling_group_name = "redacted"
  default_result         = "ABANDON" 
  heartbeat_timeout      = 300
  lifecycle_transition   = "autoscaling:EC2_INSTANCE_TERMINATING"
  notification_metadata = "foobar"
}

Debug Output

Crash Output

Expected Behavior

After applying a plan, then running another plan without changing any configuration files, should not show changes need to be updated on aws_autoscaling_lifecycle_hook.

Actual Behavior

The plan shows the notification_metadata needs to be changed to null even though the plan and apply should have done that.

Steps to Reproduce

  1. terraform plan the above configuration
  2. terraform apply
  3. Delete the notification_metadata line
  4. terraform plan
  5. terraform apply
Terraform will perform the following actions:

  # aws_autoscaling_lifecycle_hook.test will be updated in-place
  ~ resource "aws_autoscaling_lifecycle_hook" "test" {
        id                     = "redacted"
        name                   = "redacted"
      - notification_metadata  = "foobar" -> null
        # (4 unchanged attributes hidden)
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_autoscaling_lifecycle_hook.test: Modifying... [id=redacted]
aws_autoscaling_lifecycle_hook.test: Modifications complete after 1s [id=redacted]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Now run another plan. It will look identical to the above even though that shouldn't happen.

Additional Context

References

Nabushika commented 2 years ago

I'm hitting a similar problem, I believe it's because terraform doesn't actually change the notification_metadata, it stays what it was first created as

Nabushika commented 2 years ago

I think it may be the same for other attributes (at least name, haven't checked others)

Nabushika commented 2 years ago

I believe this is intended - see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#:~:text=Terraform%20has%20two%20types%20of%20ways%20you%20can%20add%20lifecycle%20hooks

github-actions[bot] commented 1 month ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!