Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: aws_auto_scalinggroup.instance_refresh.auto_rollback fails #29830

Closed
petemounce opened this issue Mar 7, 2023 · 3 comments · Fixed by #31715
Closed

[Bug]: aws_auto_scalinggroup.instance_refresh.auto_rollback fails #29830

petemounce opened this issue Mar 7, 2023 · 3 comments · Fixed by #31715
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.

Comments

@petemounce
Copy link

Terraform Core Version

1.3.7

AWS Provider Version

4.57.0

Affected Resource(s)

  • aws_autoscaling_group

Expected Behavior

An instance-refresh is initiated

  • ... with auto-rollback in case instances report Unhealthy (as in, set-instance-health)
    • ... where the original launch_template version is the version rolled back to

Actual Behavior

An API-side error:

Error: starting Auto Scaling Group (canary-aws-eu-central-1-dev-probers-2546c63e1107f566-autoscaling-rolling) instance refresh: ValidationError: The request isn't valid. The AutoRollback parameter cannot be set to true when the DesiredConfiguration parameter is empty. Set AutoRollback to false or specify a desired configuration and try again.
│ 	status code: 400, request id: b8d2600b-bd0a-4bfc-a7a2-f7975e1cbb6b

(
I think this makes sense; the autoscaling_group.instance_refresh provider docs state:

Depending on health check settings and group size, an instance refresh may take a long time or fail. This resource does not wait for the instance refresh to complete.

Upstream API documentation "undo an instance-refresh" suggests there're parameters that need to be passed when starting the instance-refresh, that when I looked into the 4.57.0 tag, are not.

I think/hope this would be addressable by adding to the request-builder the part that is necessary when auto-rollback == true. I think terraform could reasonably set "desired_configuration.launch_template.version" to the before-apply version as the thing to roll back to.
)

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}

resource "aws_launch_template" "probers" {
  name = "probers-template"

  image_id                             = data.aws_ami.ami.id
  instance_initiated_shutdown_behavior = "terminate"
  instance_type                        = "t4g.nano"
}

resource "aws_autoscaling_group" "probers" {
  name  = "autoscaling-rolling"

  launch_template {
    id      = aws_launch_template.probers.id
    version = aws_launch_template.probers.latest_version
  }
  min_size                  = 1
  max_size                  = 1
  desired_capacity          = 1
  health_check_type         = "EC2"
  health_check_grace_period = 20
  wait_for_capacity_timeout = "5m"

  # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#instance_refresh
  # https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-refresh.html
  instance_refresh {
    strategy = "Rolling"
    preferences {
      auto_rollback = true

      # https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#min_healthy_percentage
      # instances will be terminated then replaced; make sure there is "space" within the max vs desired for
      # 100 - min_healthy_percentage to be out of service.
      min_healthy_percentage = 75
      skip_matching          = false
    }
  }
}

Steps to Reproduce

  1. terraform apply the configuration
  2. change something in the launch_template - instance-type say - that will cause the launch_template version to change
  3. terraform apply
  4. observe the error from auto-rollback needing desired-configuration

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@petemounce petemounce added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Mar 7, 2023
@github-actions
Copy link

github-actions bot commented Mar 7, 2023

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels Mar 7, 2023
@justinretzolk justinretzolk removed service/ec2 Issues and PRs that pertain to the ec2 service. needs-triage Waiting for first response or review from a maintainer. labels Mar 7, 2023
@ewbankkit
Copy link
Contributor

Relates #29513.

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/autoscaling Issues and PRs that pertain to the autoscaling service.
Projects
None yet
3 participants