-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasg.tf
76 lines (62 loc) · 1.83 KB
/
asg.tf
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
resource "aws_ami_from_instance" "webserver_ami" {
source_instance_id = aws_instance.WebServer.id
name = "webserver-ami"
}
resource "aws_launch_template" "promet_temp" {
name_prefix = "PROmet-Temp"
image_id = aws_ami_from_instance.webserver_ami.id
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = 8
volume_type = "gp2"
}
}
tag_specifications {
resource_type = "instance"
tags = {
Name = "PROmet-Temp"
}
}
monitoring {
enabled = true
}
instance_type = "t2.micro"
key_name = aws_key_pair.webserver_keypair.key_name
vpc_security_group_ids = [aws_security_group.WebServer-sg.id]
placement {
availability_zone = "ap-northeast-2c"
}
}
resource "aws_autoscaling_group" "asg_promet" {
name_prefix = "ASG-PROmet"
max_size = 2
min_size = 1
desired_capacity = 1
vpc_zone_identifier = [aws_subnet.application-subnet-1.id, aws_subnet.application-subnet-2.id]
launch_template {
id = aws_launch_template.promet_temp.id
version = "$Latest"
}
target_group_arns = [aws_lb_target_group.alb-g.arn]
health_check_type = "ELB"
tag {
key = "Name"
value = "ASG-PROmet"
propagate_at_launch = true
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_autoscaling_policy" "asg-policy" {
name = "ASG-policy"
policy_type = "TargetTrackingScaling"
autoscaling_group_name = aws_autoscaling_group.asg_promet.name
target_tracking_configuration {
target_value = 50
predefined_metric_specification {
predefined_metric_type = "ASGAverageCPUUtilization"
}
}
}