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.85k stars 9.19k forks source link

Update on dependencies causes aws_autoscaling_notification to error on update #11283

Open kdanga opened 4 years ago

kdanga commented 4 years ago

Community Note

Terraform Version

0.12.18

Affected Resource(s)

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

resource "aws_autoscaling_group" "test-asg" {

  launch_configuration      = "${aws_launch_configuration.test-lc.id}"
  max_size                  = 1
  min_size                  = 0
  desired_capacity          = 0

  availability_zones = ["${var.availability_zone}"]

  # interpolate the LC into the ASG name so it always forces an update
  name                = "${aws_launch_configuration.test-lc.name}-asg"
  vpc_zone_identifier = ["${var.subnet}"]
}

resource "aws_launch_configuration" "test-lc" {
  name_prefix = "terraform-test-lc-${var.build}"

  root_block_device {
    volume_type           = "gp2"
    delete_on_termination = true
  }

  image_id             = "${var.image_id}"
  instance_type        = "${var.instance_id}"

  ebs_optimized = true
}

resource "aws_autoscaling_notification" "test-asg-notification" {
  group_names   = ["${aws_autoscaling_group.test-asg.name}"]
  notifications = ["autoscaling:EC2_INSTANCE_TERMINATE"]
  topic_arn     = "${aws_sns_topic.topic.arn}"
}

variable "build" {}

Debug Output

Expected Behavior

When forcing an update on the aws_launch_configuration resource, terraform should update the dependencies without any errors.

Actual Behavior

The aws_autoscaling_notification tries to do an update after both dependencies on aws_autoscaling_group and aws_launch_configuration were replaced. Fails with the following error:

aws_autoscaling_group.test-asg: Destroying... [id=terraform-test-lc-320191213192730297300000001-asg]
aws_autoscaling_group.test-asg: Still destroying... [id=terraform-test-lc-320191213192730297300000001-asg, 10s elapsed]
aws_autoscaling_group.test-asg: Still destroying... [id=terraform-test-lc-320191213192730297300000001-asg, 20s elapsed]
aws_autoscaling_group.test-asg: Destruction complete after 22s
aws_launch_configuration.test-lc: Destroying... [id=terraform-test-lc-320191213192730297300000001]
aws_launch_configuration.test-lc: Destruction complete after 1s
aws_launch_configuration.test-lc: Creating...
aws_launch_configuration.test-lc: Creation complete after 5s [id=terraform-test-lc-220191213192847027200000001]
aws_autoscaling_group.test-asg: Creating...
aws_autoscaling_group.test-asg: Creation complete after 3s [id=terraform-test-lc-220191213192847027200000001-asg]
aws_autoscaling_notification.test-asg-notification: Modifying... [id=arn:aws:sns:us-east-1:494976196876:vrs-alertTermination]

Error: Error deleting notification configuration for ASG "terraform-test-lc-320191213192730297300000001-asg", Topic ARN "arn:aws:sns:us-east-1:494976196876:vrs-alertTermination"

Steps to Reproduce

  1. terraform apply and provide build valueof 1
  2. terraform apply again, but with build value of 2

Important Factoids

References

lystopad commented 3 years ago

Hi, Same for me with terraform v0.14.11 and aws provider v3.42.0.

mehmetyazicioglu commented 3 years ago

hello, i am having the same issue with terraform v.0.14.11 and aws provider v3.42.0.

lystopad commented 3 years ago

@kdanga , hi I solved it with the following explicit configuration for ASG and LC resources:

    lifecycle {
        create_before_destroy = true
    }

After that terraform is not complaining. Pls, try it.

justinretzolk commented 3 years ago

Hey y'all 👋 Thank you for taking the time to file this, and for the additional discussion around it! Given the workaround provided above, and that there's been a number of AWS provider releases since this was initially field, can anyone confirm whether they're still experiencing this behavior?

github-actions[bot] commented 1 day 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!