-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasg.tf
76 lines (59 loc) · 1.67 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
data "template_file" "init" {
template = "${file("${path.module}/wordpress.sh")}"
}
#launch template
resource "aws_launch_template" "example" {
name_prefix = "example"
image_id = "${data.aws_ami.image.id}"
instance_type = "c5.large"
key_name = "${aws_key_pair.us-east-1-key.key_name}"
vpc_security_group_ids = ["${aws_security_group.asg-sec-group.id}"]
user_data = "${base64encode(data.template_file.init.rendered)}"
}
resource "aws_autoscaling_group" "example" {
availability_zones = [
"${var.region}a",
"${var.region}b",
"${var.region}c",
]
desired_capacity = "${var.desired_capacity}"
max_size = "${var.max_size}"
min_size = "${var.min_size}"
mixed_instances_policy {
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"
}
}
}
}
###Launch config##
# resource "aws_launch_configuration" "as_conf" {
# name = "web_config"
# image_id = "${data.aws_ami.image.id}"
# instance_type = "t2.micro"
# user_data = "${file("wordpress.sh")}"
# spot_price = "0.1"
# }
# resource "aws_autoscaling_group" "bar" {
# name = "terraform-asg-example"
# launch_configuration = "${aws_launch_configuration.as_conf.name}"
# availability_zones = [
# "us-east-1a",
# "us-east-1b",
# "us-east-1c",
# ]
# min_size = 1
# max_size = 2
# lifecycle {
# create_before_destroy = true
# }
# }