티스토리 뷰

필요한 것

launch_configuration, launch_template 또는 mixed_instances_policy 가 필요

 

 

예제는 terraform docs에서 가져옴

Launch Tmeplate 과 함께 사용

resource "aws_autoscaling_group" "bar" {
  availability_zones = ["us-east-1a"]
  desired_capacity   = 1
  max_size           = 1
  min_size           = 1

  launch_template {
    id      = aws_launch_template.foobar.id
    version = "$Latest"   # 또는 aws_launch_template.example.latest_version
  }
}

 

availability zones (옵션) - vpc_zone_identifider와 함께 사용하면 conflict 가 발생
- launch template 과 default subnet  으로부터 ec2에 network interface 를 부여함

 

Mixed Instances Policy

resource "aws_launch_template" "example" {
  name_prefix   = "example"
  image_id      = data.aws_ami.example.id
  instance_type = "c5.large"
}

resource "aws_autoscaling_group" "example" {
  capacity_rebalance  = true
  desired_capacity    = 12
  max_size            = 15
  min_size            = 12
  vpc_zone_identifier = [aws_subnet.example1.id, aws_subnet.example2.id]

  mixed_instances_policy {
    instances_distribution {
      on_demand_base_capacity                  = 0
      on_demand_percentage_above_base_capacity = 25
      spot_allocation_strategy                 = "capacity-optimized"
    }

    launch_template {
      launch_template_specification {
        launch_template_id = aws_launch_template.example.id
      }

      override {
        instance_type     = "c4.large"
        weighted_capacity = "3"
      }

      override {
        instance_type     = "c3.large"
        weighted_capacity = "2"
      }
    }
  }
}
capacity_rebalance (옵션) capacity rebalance( 용량 재조정)이 enabled / disabled 인지 여부
vpc_zone_identifier (옵션) 리소스들을 생성할 subnet ID 리스트 (subnet이 어떤 availability zone에 있는지 자동으로 알아냄)
mized_instance_policy (옵션) asg에 launch할 target 을 정의한 블록
override (옵션) 여러개의 인스턴스 타입을 명시하게 해줌
-> launch template의 똑같은 파라미터를 오버라이드함
weighted_capacity (옵션) 다른 인스턴스 타입과 비례되는 가중치를 부여

 

Instance Refresh

https://docs.aws.amazon.com/autoscaling/ec2/userguide/asg-instance-refresh.html

 

Replace Auto Scaling instances based on an instance refresh - Amazon EC2 Auto Scaling

We recommend that you do not clear this check box. Only clear it if you want to stop using a mixed instances policy. After the instance refresh succeeds, Amazon EC2 Auto Scaling updates your group to match the Desired configuration. If it no longer include

docs.aws.amazon.com

  instance_refresh {
    strategy = "Rolling"
    preferences {
      min_healthy_percentage = 50
    }
    triggers = ["tag"]
  }
}
strategy (필수) 인스턴스를 재시작하는 전략 (Rolling 만 허용됨)
Preferences (옵션) 디폴트 파라미터를 오버라이드
min_healthy_percentage: 인스턴스가 재시작 되는 동안 asg안에 유지되어야하는 용량(디폴트는 90퍼센트)
checkpoint_delay: 체크포인트 후 기다리는 시간 (디폴트는 3600초)
instance_warmup: 새로운 인스턴스가 사용할 준비가 되기까지의 시간 (디폴트는 asg의 health check grace period)
trigger (옵션) 인스턴스를 재시작을 triggger하는 속성 이름
(launch_configuration, launch_template, mixed_instance_policy를 변경할때 무조건 인스턴스 재식작이 trigger됨)

- 인스턴스 재시작을 trigger하려면 version이 aws_launch_template.latest_ver으로 셋팅되어야 함

- 한번에 한개의 인스턴스만 재시작함 (이 리소스가 업데이트 되면, 나머지  존재하는 재시작은 취소됨)

name_prefix = "my-asg-${aws_launch_template.this.latest_version}-"

으로 네이밍해도 좋을거 같음

 

Warm Pool

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

  warm_pool {
    pool_state                  = "Hibernated"
    min_size                    = 1
    max_group_prepared_capacity = 10

    instance_reuse_policy {
      reuse_on_scale_in = true
    }
  }
}
pool_state (옵션) 인스턴스의 라이프사이클이 끝난 후 인스턴스의 상태를 변경
선택할 수 있는 값: stopped(default), running, hibernated
min_size (옵션) warm pool 내에서 유지할 인스턴스의 최소 갯수 (default 0)
instance_reuse_policy (옵션) ASG의 인스턴스 축소시 warm pool로 반환할 수 있는지 여부 (default 는 인스턴스 종료)
max_group_prepared_capacity (옵션) warm pool에 있을 수 있는 최대 인스턴스 갯수 (terminate 된것 제외)

 

Tag의 Propagate_at_launch 옵션

인스턴스를 생성시킬때, asg에 정의된 태그를 추가할 거면 True

asg에 해당되는 태그를 정의하는 거라면 False

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함