-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgocdsrv_hst.tf
executable file
·101 lines (82 loc) · 2.47 KB
/
gocdsrv_hst.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
## GoCD server hosts + launch config + autoscaling group + security group
# Security group
resource "aws_security_group" "gocdsrv_hst" {
name = "${var.env_name}-gocdsrv-hst"
vpc_id = "${aws_vpc.rancher.id}"
description = "GoCD server hosts"
ingress {
from_port = 500
to_port = 500
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 4500
to_port = 4500
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8153
to_port = 8154
protocol = "tcp"
cidr_blocks = ["${var.my_ip}/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
Name = "${var.env_name}-gocdsrv-hst"
}
}
# User-data template
data "template_file" "userdata_gocdsrv_hst" {
template = "${file("./files/userdata_gocdsrv_hst.template")}"
vars {
# HostsReg
env_name = "${var.env_name}"
dns_zone = "${var.dns_zone}"
reg_token = "${var.reg_token}"
}
}
# Launch configuration
resource "aws_launch_configuration" "gocdsrv_hst" {
image_id = "${lookup(var.ami_type, var.aws_region)}"
instance_type = "${var.gocdsrv_hst_size}"
key_name = "${var.key_name}"
security_groups = ["${aws_security_group.gocdsrv_hst.id}"]
iam_instance_profile = "${aws_iam_instance_profile.rancher.id}"
associate_public_ip_address = true
lifecycle {
create_before_destroy = true
}
depends_on = ["aws_internet_gateway.igw"]
user_data = "${data.template_file.userdata_gocdsrv_hst.rendered}"
}
# Autoscaling group
resource "aws_autoscaling_group" "gocdsrv_hst" {
name = "${var.env_name}-gocdsrv-hst"
availability_zones = ["${var.aws_region}a"]
launch_configuration = "${aws_launch_configuration.gocdsrv_hst.name}"
health_check_grace_period = 500
health_check_type = "EC2"
max_size = "${var.gocdsrv_hst_max}"
min_size = "${var.gocdsrv_hst_min}"
desired_capacity = "${var.gocdsrv_hst_des}"
vpc_zone_identifier = ["${aws_subnet.pub_a.id}"]
tag {
key = "Name"
value = "${var.env_name}-gocdsrv-hst"
propagate_at_launch = true
}
depends_on = ["aws_launch_configuration.gocdsrv_hst"]
}