-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinfra.tf
106 lines (97 loc) · 2.98 KB
/
infra.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
resource "aws_launch_template" "master" {
count = var.master_node_count
name_prefix = substr("${local.name}-master-${count.index}", 0, 32)
image_id = data.aws_ami.default_ami.id
instance_type = var.master_instance_type
user_data = data.template_cloudinit_config.init-master[count.index].rendered
key_name = var.key_name
iam_instance_profile {
name = aws_iam_instance_profile.master_profile.name
}
block_device_mappings {
device_name = "/dev/sda1"
ebs {
encrypted = true
volume_type = "gp2"
volume_size = var.master_root_volume_size
}
}
network_interfaces {
delete_on_termination = true
security_groups = concat([aws_security_group.master.id], var.master_security_group_ids)
}
tags = local.common_tags
}
resource "aws_launch_template" "worker" {
for_each = local.worker_groups_map
name_prefix = substr("${local.name}-worker-${each.key}", 0, 32)
image_id = data.aws_ami.default_ami.id
instance_type = each.value.instance_type
user_data = data.template_cloudinit_config.init-worker[each.key].rendered
key_name = var.key_name
iam_instance_profile {
name = aws_iam_instance_profile.worker_profile.name
}
block_device_mappings {
device_name = "/dev/sda1"
ebs {
encrypted = true
volume_type = "gp2"
volume_size = each.value.root_volume_size
}
}
network_interfaces {
delete_on_termination = true
security_groups = concat([aws_security_group.worker.id], each.value.additional_security_group_ids)
}
tags = local.common_tags
}
resource "aws_autoscaling_group" "master" {
count = var.master_node_count
name_prefix = substr("${local.name}-master-${count.index}", 0, 32)
desired_capacity = 1
max_size = 1
min_size = 1
vpc_zone_identifier = var.public_subnets
target_group_arns = [
aws_lb_target_group.kubeapi.arn
]
launch_template {
id = aws_launch_template.master[count.index].id
version = "$Latest"
}
dynamic "tag" {
for_each = local.master_tags
content {
key = tag.value.key
propagate_at_launch = tag.value.propagate_at_launch
value = tag.value.value
}
}
depends_on = [
aws_lb.kubeapi
]
}
resource "aws_autoscaling_group" "worker" {
for_each = local.worker_groups_map
name_prefix = substr("${local.name}-worker-${each.key}", 0, 32)
max_size = each.value.max_size
min_size = each.value.min_size
desired_capacity = each.value.desired_capacity
vpc_zone_identifier = var.public_subnets
launch_template {
id = aws_launch_template.worker[each.key].id
version = "$Latest"
}
dynamic "tag" {
for_each = local.master_tags
content {
key = tag.value.key
propagate_at_launch = tag.value.propagate_at_launch
value = tag.value.value
}
}
depends_on = [
aws_lb.kubeapi
]
}