-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcontrol-planes.tf
130 lines (114 loc) · 4.65 KB
/
control-planes.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
locals {
control_plane_names = [for i in range(var.control_plane_count) : format("ip-10-0-1-%d.%s.compute.internal", 10 + i, var.region)]
}
resource "tls_private_key" "control-planes" {
count = var.control_plane_count
algorithm = "ED25519"
}
resource "tls_private_key" "control-planes-sshd" {
count = var.control_plane_count
algorithm = "ED25519"
}
resource "local_file" "control-planes-pem" {
count = var.control_plane_count
filename = "${path.module}/control-planes/control-plane-${count.index}.pem"
content = tls_private_key.control-planes[count.index].private_key_openssh
file_permission = "0600"
}
resource "outscale_keypair" "control-planes" {
count = var.control_plane_count
public_key = tls_private_key.control-planes[count.index].public_key_openssh
}
resource "outscale_public_ip" "control-planes" {
count = var.public_cloud ? var.control_plane_count : 0
}
resource "outscale_public_ip_link" "control-planes" {
count = var.public_cloud ? var.control_plane_count : 0
vm_id = outscale_vm.control-planes[count.index].vm_id
public_ip = outscale_public_ip.control-planes[count.index].public_ip
}
resource "outscale_security_group" "control-plane" {
description = "Kubernetes control-planes (${var.cluster_name})"
net_id = var.public_cloud ? null : outscale_net.net[0].net_id
}
resource "outscale_security_group_rule" "control-plane-ssh" {
flow = "Inbound"
security_group_id = outscale_security_group.control-plane.id
rules {
from_port_range = "22"
to_port_range = "22"
ip_protocol = "tcp"
ip_ranges = var.public_cloud ? ["0.0.0.0/0"] : ["10.0.0.0/24"]
}
# etcd
rules {
from_port_range = "2379"
to_port_range = "2380"
ip_protocol = "tcp"
ip_ranges = var.public_cloud ? [for i in range(var.control_plane_count) : format("%s/32", outscale_public_ip.control-planes[i].public_ip)] : ["10.0.1.0/24"]
}
# kube-apiserver
rules {
from_port_range = "6443"
to_port_range = "6443"
ip_protocol = "tcp"
ip_ranges = var.public_cloud ? ["0.0.0.0/0"] : ["10.0.0.0/16"]
}
}
resource "outscale_vm" "control-planes" {
count = var.control_plane_count
image_id = outscale_image.node.image_id
vm_type = var.control_plane_vm_type
keypair_name = outscale_keypair.control-planes[count.index].keypair_name
security_group_ids = [outscale_security_group.control-plane.security_group_id, outscale_security_group.node.security_group_id, outscale_security_group.worker.security_group_id]
subnet_id = var.public_cloud ? null : outscale_subnet.nodes[0].subnet_id
private_ips = var.public_cloud ? null : [format("10.0.1.%d", 10 + count.index)]
user_data = base64encode(format("#cloud-config\nssh:\n emit_keys_to_console: false\nssh_keys:\n ed25519_private: |\n %s\n ed25519_public: %s",
indent(4, tls_private_key.control-planes-sshd[count.index].private_key_openssh),
replace(tls_private_key.control-planes-sshd[count.index].public_key_openssh, "\n", "")))
provisioner "remote-exec" {
inline = ["echo ok"]
connection {
type = "ssh"
user = "outscale"
host = var.public_cloud ? self.public_ip : format("10.0.1.%d", 10 + count.index)
private_key = tls_private_key.control-planes[count.index].private_key_openssh
bastion_host = var.public_cloud ? null : outscale_public_ip.bastion.public_ip
bastion_private_key = var.public_cloud ? null : tls_private_key.bastion.private_key_openssh
bastion_user = var.public_cloud ? null : "outscale"
bastion_port = var.public_cloud ? null : 22
}
}
block_device_mappings {
device_name = "/dev/sda1"
bsu {
delete_on_vm_deletion = true
volume_size = var.control_plane_volume_size
volume_type = var.control_plane_volume_type
iops = var.control_plane_volume_type == "io1" ? var.control_plane_iops : null
}
}
tags {
key = "name"
value = "${var.cluster_name}-control-plane-${count.index}"
}
tags {
key = "OscK8sNodeName"
value = local.control_plane_names[count.index]
}
dynamic "tags" {
for_each = var.public_cloud ? [1] : []
content {
key = "osc.fcu.eip.auto-attach"
value = outscale_public_ip.control-planes[count.index].public_ip
}
}
}
resource "outscale_tag" "control-planes-k8s-cluster-name" {
count = var.control_plane_count
resource_ids = [outscale_vm.control-planes[count.index].vm_id]
tag {
key = "OscK8sClusterID/${var.cluster_name}"
value = "owned"
}
}