terraform-deploy-wordpress-site / instance-ASG.tf
instance-ASG.tf
Raw
resource "aws_autoscaling_group" "serverASG" {
  name     = "serverASG"
  min_size = 2
  max_size = 3

  health_check_type = "EC2"

  vpc_zone_identifier = [
    aws_subnet.server_subnetA.id,
    aws_subnet.server_subnetB.id
  ]

  target_group_arns = [aws_lb_target_group.serverTG.arn]

  mixed_instances_policy {
    launch_template {
      launch_template_specification {
        launch_template_id = aws_launch_template.server.id
      }
      
    }
  }
}

resource "aws_autoscaling_policy" "asgpolicy" {
  name                   = "asgpolicy"
  policy_type            = "TargetTrackingScaling"
  autoscaling_group_name = aws_autoscaling_group.serverASG.name

  estimated_instance_warmup = 300

  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }

    target_value = 25.0
  }
}