EC2 ASG 생성하기
AWS Auto Scaling Group은 Amazon Web Services(AWS)에서 제공하는 서비스로, 클라우드 인프라 내의 리소스를 자동으로 확장하거나 축소할 수 있게 해주는 기능입니다. 사용자의 애플리케이션이 겪는 트래픽의 변화에 따라 필요한 컴퓨팅 리소스를 동적으로 조정하여, 최적의 성능을 유지하면서 비용을 효율적으로 관리할 수 있습니다.
##### ASG
resource "aws_launch_template" "lt" {
name_prefix = "${var.service_name}-${var.vpc_name}-LT"
image_id = var.image_id
instance_type = var.instance_type
key_name = var.key_name
vpc_security_group_ids = [aws_security_group.ec2.id]
tag_specifications {
resource_type = "instance"
tags = {
Name = "${var.service_name}-${var.vpc_name}-LaunchTemplate"
}
}
}
resource "aws_autoscaling_group" "asg" {
launch_template {
id = aws_launch_template.lt.id
version = "$Latest"
}
min_size = var.min_size
max_size = var.max_size
desired_capacity = var.desired_capacity
vpc_zone_identifier = var.private_subnets
target_group_arns = [aws_lb_target_group.internal.arn]
tag {
key = "Name"
value = "${var.service_name}-${var.vpc_name}-asg"
propagate_at_launch = true
}
}
Last updated
Was this helpful?