-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathec2.tf
73 lines (62 loc) · 2.08 KB
/
ec2.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
data "aws_ami" "ubuntu" {
owners = ["amazon"]
most_recent = true
name_regex = "ubuntu"
filter {
name = "architecture"
values = ["x86_64"]
}
}
resource "aws_launch_template" "this" {
name_prefix = "terraform-"
image_id = data.aws_ami.ubuntu.id
instance_type = var.instance_type
key_name = var.instance_key_name
user_data = filebase64("ec2_setup.sh")
monitoring {
enabled = true
}
network_interfaces {
associate_public_ip_address = true
delete_on_termination = true
security_groups = [aws_security_group.autoscaling.id]
}
}
resource "aws_autoscaling_group" "this" {
name = "autoscaling-terraform-application-auto-scaling"
vpc_zone_identifier = [aws_subnet.this["pub_a"].id, aws_subnet.this["pub_b"].id]
max_size = 5
min_size = 2
health_check_grace_period = 240
health_check_type = "ELB"
force_delete = true
target_group_arns = [aws_lb_target_group.this.id]
launch_template {
id = aws_launch_template.this.id
version = aws_launch_template.this.latest_version
}
}
resource "aws_autoscaling_policy" "scaleup" {
name = "Scale Up"
autoscaling_group_name = aws_autoscaling_group.this.name
adjustment_type = "ChangeInCapacity"
scaling_adjustment = "1"
cooldown = "180"
policy_type = "SimpleScaling"
}
resource "aws_autoscaling_policy" "scaledown" {
name = "Scale Down"
autoscaling_group_name = aws_autoscaling_group.this.name
adjustment_type = "ChangeInCapacity"
scaling_adjustment = "-1"
cooldown = "180"
policy_type = "SimpleScaling"
}
resource "aws_instance" "jenkins" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
vpc_security_group_ids = [aws_security_group.jenkins.id]
subnet_id = aws_subnet.this["pvt_b"].id
availability_zone = "${var.aws_region}b"
tags = merge(local.common_tags, { Name = "Jenkins Machine" })
}