forked from solidnerd/terraform-k8s-hcloud
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path01-main.tf
executable file
·105 lines (89 loc) · 2.7 KB
/
01-main.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
provider "hcloud" {
token = var.hcloud_token
}
resource "hcloud_ssh_key" "k8s_admin" {
name = "k8s_admin"
public_key = file(var.ssh_public_key)
}
resource "hcloud_network" "kubenet" {
name = "kubenet"
ip_range = "10.88.0.0/16"
}
resource "hcloud_network_subnet" "kubenet" {
network_id = hcloud_network.kubenet.id
type = "server"
network_zone = "eu-central"
ip_range = "10.88.0.0/16"
}
resource "hcloud_load_balancer" "kube_load_balancer" {
name = "kube-lb"
load_balancer_type = "lb11"
location = var.location
}
resource "hcloud_load_balancer_service" "kube_load_balancer_service" {
load_balancer_id = hcloud_load_balancer.kube_load_balancer.id
protocol = "tcp"
listen_port = 6443
destination_port = 6443
}
resource "hcloud_server" "master" {
depends_on = [hcloud_load_balancer.kube_load_balancer]
count = var.master_count
name = "${var.cluster_name}-master-${count.index + 1}"
location = var.location
server_type = var.master_type
image = var.master_image
ssh_keys = [hcloud_ssh_key.k8s_admin.id]
connection {
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "scripts/bootstrap.sh"
destination = "/root/bootstrap.sh"
}
provisioner "remote-exec" {
inline = ["SSH_PORT=${var.ssh_port} bash /root/bootstrap.sh"]
}
}
resource "hcloud_server" "node" {
count = var.node_count
name = "${var.cluster_name}-node-${count.index + 1}"
server_type = var.node_type
image = var.node_image
location = var.location
depends_on = [hcloud_server.master]
ssh_keys = [hcloud_ssh_key.k8s_admin.id]
connection {
host = self.ipv4_address
type = "ssh"
private_key = file(var.ssh_private_key)
}
provisioner "file" {
source = "scripts/bootstrap.sh"
destination = "/root/bootstrap.sh"
}
provisioner "remote-exec" {
inline = ["SSH_PORT=${var.ssh_port} bash /root/bootstrap.sh"]
}
}
resource "hcloud_server_network" "master_network" {
count = var.master_count
depends_on = [hcloud_server.master]
server_id = hcloud_server.master[count.index].id
network_id = hcloud_network.kubenet.id
}
resource "hcloud_load_balancer_target" "load_balancer_target" {
count = var.master_count
depends_on = [hcloud_server.master]
type = "server"
server_id = hcloud_server.master[count.index].id
load_balancer_id = hcloud_load_balancer.kube_load_balancer.id
}
resource "hcloud_server_network" "node_network" {
count = var.node_count
depends_on = [hcloud_server.node]
server_id = hcloud_server.node[count.index].id
network_id = hcloud_network.kubenet.id
}