-
Notifications
You must be signed in to change notification settings - Fork 5
/
autoscaling_master.tf
145 lines (121 loc) · 3.66 KB
/
autoscaling_master.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
data "aws_vpc" "selected" {
id = "${var.vpc}"
}
data "aws_subnet" "region_1a" {
id = "${var.subnets[0]}"
}
data "template_file" "master" {
template = "${file("${path.module}/scripts/userdata.tpl")}"
vars {
s3_id = "${aws_s3_bucket.cluster.id}"
role = "master"
proxy = "${replace("${var.proxy_servers}", ",", " ")}"
volume = "${aws_ebs_volume.master.id}"
load_balancer_dns = "${aws_lb.master.dns_name}"
net_plugin = "${var.cluster_network_plugin}"
}
}
resource "aws_ebs_volume" "master" {
availability_zone = "${data.aws_subnet.region_1a.availability_zone}"
size = 40
encrypted = true
type = "gp2"
tags = "${merge(var.additional_tags, map("Name", "${var.name}-master"))}"
}
resource "aws_security_group" "master" {
name_prefix = "${var.name}-master"
description = "${var.name}-master"
vpc_id = "${var.vpc}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = ["${aws_security_group.nodes.id}"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = "${var.additional_tags}"
}
resource "aws_launch_configuration" "master" {
name_prefix = "${var.name}-master-"
image_id = "${data.aws_ami.ubuntu.id}"
instance_type = "${var.master_instance_type}"
security_groups = ["${aws_security_group.master.id}"]
key_name = "${var.ssh_key}"
user_data = "${data.template_file.master.rendered}"
iam_instance_profile = "${aws_iam_instance_profile.cluster.id}"
root_block_device {
volume_size = 60
volume_type = "gp2"
}
lifecycle {
create_before_destroy = true
ignore_changes = ["image_id"]
}
}
resource "aws_autoscaling_group" "master" {
name_prefix = "${var.name}-master-"
max_size = 1
min_size = 1
health_check_grace_period = 300
health_check_type = "EC2"
desired_capacity = 1
force_delete = true
launch_configuration = "${aws_launch_configuration.master.name}"
vpc_zone_identifier = ["${data.aws_subnet.region_1a.id}"]
target_group_arns = ["${aws_lb_target_group.master_443.arn}"]
tags = ["${concat(
list(map("key", "Name", "value", "${var.name}-master", "propagate_at_launch", true),
map("key", "KubernetesCluster", "value", "${var.name}", "propagate_at_launch", true),
map("key", "k8s.io/role/master", "value", 1, "propagate_at_launch", true),
),
local.tags_asg_format
)}"]
lifecycle {
create_before_destroy = true
}
}
resource "aws_lb" "master" {
name = "${var.name}-master"
internal = true
subnets = ["${data.aws_subnet.region_1a.id}"]
load_balancer_type = "network"
tags = "${merge(var.additional_tags, map("Name", "${var.name}-master"))}"
}
resource "aws_lb_listener" "master" {
load_balancer_arn = "${aws_lb.master.arn}"
port = "443"
protocol = "TCP"
default_action {
target_group_arn = "${aws_lb_target_group.master_443.arn}"
type = "forward"
}
}
resource "aws_lb_target_group" "master_443" {
name = "${var.name}-master-443"
port = 443
protocol = "TCP"
vpc_id = "${var.vpc}"
}