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.74k stars 9.09k forks source link

Autoscaling groups and launchconfiguration sometimes fail with create_before_destroy #13082

Open vdmkenny opened 4 years ago

vdmkenny commented 4 years ago

Community Note

Terraform Version

Terraform v0.12.24

Affected Resource(s)

Terraform Configuration Files

resource "aws_launch_configuration" "example-application" {
  name_prefix = "example-application_"
  image_id = data.aws_ssm_parameter.example-application.value
  instance_type = "m5a.large"
  security_groups = [aws_security_group.allow_internal.id]
  key_name = "jump"

  root_block_device {
    volume_size = "16"
    volume_type = "gp2"
    delete_on_termination = true
    encrypted = true
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_autoscaling_group" "example-application" {
  name = aws_launch_configuration.example-application.name
  min_size = "1"
  max_size = "1"
  launch_configuration = aws_launch_configuration.example-application.id
  health_check_type = "EC2"
  termination_policies = ["OldestLaunchConfiguration"]
  vpc_zone_identifier = [aws_subnet.app-zone-A.id, aws_subnet.app-zone-B.id, aws_subnet.app-zone-C.id]

  tags = [
    {
      key                 = "Name"
      value               = "example-application"
      propagate_at_launch = true
    }
  ]
  lifecycle {
     create_before_destroy = true
   }
}

Debug Output

aws_autoscaling_group.example-application: Still creating... [10s elapsed]
aws_autoscaling_group.example-application: Still creating... [20s elapsed]
aws_autoscaling_group.example-application: Still creating... [30s elapsed]
aws_autoscaling_group.example-application: Still creating... [40s elapsed]
aws_autoscaling_group.example-application: Creation complete after 49s [id=example-application_20200429101734739100000001]
aws_autoscaling_group.example-application: Destroying... [id=example-application_20200429100508913100000002]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 10s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 20s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 30s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 40s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 50s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 1m0s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 1m10s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 1m20s elapsed]
aws_autoscaling_group.example-application: Still destroying... [id=example-application_20200429100508913100000002, 1m30s elapsed]
aws_autoscaling_group.example-application: Destruction complete after 1m35s
aws_launch_configuration.example-application: Destroying... [id=example-application_20200429100508913100000002]
aws_launch_configuration.example-application: Destruction complete after 0s

Expected Behavior

The new launch configuration and autoscaling group would be created, and the old ones would be destroyed.

Actual Behavior

Sometimes, the launch configuration is created, but the autoscaling group is not. The old autoscaling group is still present and running.

Sometimes the new autoscaling groups is created, but the old one is not destroyed, causing a duplicate, older versioned, application to keep running.

Steps to Reproduce

I have not found the pattern for when this happens. It happens sometimes with above config.

  1. terraform apply

Important Factoids

The terraform apply is running in a gitlab pipeline

justinretzolk commented 2 years ago

Hey @vdmkenny 👋 Thank you for taking the time to file this! Given that there's been a number of releases of the AWS Provider since you initially filed it, can you confirm if you're still experiencing this behavior?

vdmkenny commented 2 years ago

Hello @justinretzolk , I'd love to try to reproduce this, but since it's been a year and a half since I filed this bug, I'm no longer working at the same client, and no longer have access to this or a similar environment to try it out, sorry!

I can say that the bug was present until the end of working there (April 2021) though very sporadic, and we were always on the latest version of terraform and the aws provider.

Another tidbit of information: We were using S3 to store the tf state.

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!