Search code examples
amazon-web-servicesterraformterraform-provider-aws

Autorollback during Autoscaling instance refresh through Terraform


I am trying to configure auto rollback during instance refresh for an autoscaling group but running into the following error.

Error: starting Auto Scaling Group (terraform-20230820171958436000000003) 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.

Here is my terraform configuration file (main.tf):

resource "aws_autoscaling_group" "example" {
  availability_zones = ["us-west-2a"]
  desired_capacity   = 1
  max_size           = 2
  min_size           = 1

  launch_template {
    id      = aws_launch_template.example.id
    version = aws_launch_template.example.latest_version
  }

  tag {
    key                 = "Key"
    value               = "Value"
    propagate_at_launch = true
  }

  instance_refresh {
    strategy = "Rolling"
    preferences {
      min_healthy_percentage = 50
      auto_rollback          = true
    }
  }
}

resource "aws_launch_template" "example" {
  image_id      = "ami-*********"
  instance_type = "i3.large"
}

I don't see autoscaling resource have a section with desired configuration in the tf provider here. Is this feature missing in Terraform? I do see we have options to enable this using AWS console or AWS cli.


Solution

  • It seems that the issue was fixed in the terraform provider for AWS versions >= 5.9.0. Upgrading the provider version should fix it. The difference was this:

    auto_rollback - (Optional) Automatically rollback if instance refresh fails. Defaults to false. This option may only be set to true when specifying a launch_template or mixed_instances_policy.