Defines an AWS Auto Scaling Group with a specified placement group, lifecycle hooks, and instance maintenance policies.

Terraform Template

resource "aws_autoscaling_group" "bar" {
  desired_capacity = 4
  force_delete = true
  health_check_grace_period = 300
  health_check_type = "ELB"

  initial_lifecycle_hook {
    default_result = "CONTINUE"
    heartbeat_timeout = 2000
    lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING"
    name = "foobar"
    notification_metadata = jsonencode({
 foo = "bar"
 })
    notification_target_arn = "arn:aws:sqs:us-east-1:444455556666:queue1*"
    role_arn = "arn:aws:iam::123456789012:role/S3Access"
  }

  instance_maintenance_policy {
    max_healthy_percentage = 120
    min_healthy_percentage = 90
  }
  launch_configuration = "aws_launch_configuration.foobar.name"
  max_size = 5
  min_size = 2
  name = "foobar3-terraform-test"
  placement_group = aws_placement_group.test.id

  tag {
    key = "foo"
    propagate_at_launch = true
    value = "bar"
  }

  tag {
    key = "lorem"
    propagate_at_launch = false
    value = "ipsum"
  }
  vpc_zone_identifier = ["aws_subnet.example1.id", "aws_subnet.example2.id"]
}

resource "aws_placement_group" "test" {
  name = "test"
  strategy = "cluster"
}