-
Notifications
You must be signed in to change notification settings - Fork 2
/
templates.tf
172 lines (135 loc) · 4.74 KB
/
templates.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// kube-controller-manager.sh --------------------------------------------------
data "template_file" "start_controller_manager" {
template = "${file("${path.module}/scripts/kube-controller-manager.sh")}"
depends_on = [
"triton_machine.controller",
]
vars {
master_ip = "${triton_machine.controller.0.primaryip}"
}
}
resource "local_file" "start_controller_manager" {
content = "${data.template_file.start_controller_manager.rendered}"
filename = "${path.module}/output/kube-controller-manager.sh"
}
// kube-apiserver.sh -----------------------------------------------------------
data "template_file" "start_apiserver" {
template = "${file("${path.module}/scripts/kube-apiserver.sh")}"
depends_on = [
"triton_machine.controller",
]
vars {
controller_count = "${length(triton_machine.controller.*.primaryip)}"
etcd_servers = "${join(",", formatlist("http://%s:2379", list(var.etcd1_ip, var.etcd2_ip, var.etcd3_ip)))}"
}
}
resource "local_file" "start_apiserver" {
content = "${data.template_file.start_apiserver.rendered}"
filename = "${path.module}/output/kube-apiserver.sh"
}
// kubeconfig ------------------------------------------------------------------
data "template_file" "kubeconfig" {
template = "${file("${path.module}/templates/kubeconfig.tpl")}"
depends_on = [
"triton_machine.worker",
]
vars {
secret_token = "${var.secret_token}"
master_ip = "${triton_machine.controller.0.primaryip}"
}
}
resource "local_file" "kubeconfig" {
content = "${data.template_file.kubeconfig.rendered}"
filename = "${path.module}/output/kubeconfig"
}
// kubelet.sh ------------------------------------------------------------------
data "template_file" "start_kubelet" {
template = "${file("${path.module}/scripts/kubelet.sh")}"
depends_on = [
"triton_machine.worker",
]
vars {
master_ip = "${triton_machine.controller.0.primaryip}"
}
}
resource "local_file" "start_kubelet" {
content = "${data.template_file.start_kubelet.rendered}"
filename = "${path.module}/output/kubelet.sh"
}
// kube-proxy.sh ---------------------------------------------------------------
data "template_file" "start_kube_proxy" {
template = "${file("${path.module}/scripts/kube-proxy.sh")}"
depends_on = [
"triton_machine.worker",
]
vars {
master_ip = "${triton_machine.controller.0.primaryip}"
}
}
resource "local_file" "start_kube_proxy" {
content = "${data.template_file.start_kube_proxy.rendered}"
filename = "${path.module}/output/kube-proxy.sh"
}
// token.csv -------------------------------------------------------------------
data "template_file" "token_csv" {
template = "${file("${path.module}/templates/token.csv.tpl")}"
depends_on = [
"triton_machine.controller",
]
vars {
secret_token = "${var.secret_token}"
}
}
resource "local_file" "token_csv" {
content = "${data.template_file.token_csv.rendered}"
filename = "${path.module}/output/token.csv"
}
// ssh.config ------------------------------------------------------------------
data "template_file" "ssh_config" {
template = "${file("${path.module}/templates/ssh.config.tpl")}"
vars {
bastion_ip = "${var.bastion_host}"
identity_file = "${var.triton_key_path}"
}
}
resource "local_file" "ssh_config" {
content = "${data.template_file.ssh_config.rendered}"
filename = "${path.module}/output/ssh.config"
}
// ansible-inventory -----------------------------------------------------------
data "template_file" "controller_ansible" {
count = "${triton_machine.controller.count}"
template = "${file("${path.module}/templates/hostname.tpl")}"
depends_on = [
"triton_machine.controller",
]
vars {
index = "${count.index + 1}"
name = "controller${format("%02d", count.index)}"
extra = " ansible_host=${element(triton_machine.controller.*.primaryip, count.index)}"
}
}
data "template_file" "worker_ansible" {
count = "${triton_machine.worker.count}"
template = "${file("${path.module}/templates/hostuser.tpl")}"
depends_on = [
"triton_machine.worker",
]
vars {
index = "${count.index + 1}"
name = "worker${format("%02d", count.index)}"
extra = " ansible_host=${element(triton_machine.worker.*.primaryip, count.index)}"
}
}
data "template_file" "ansible_inventory" {
template = "${file("${path.module}/templates/ansible_inventory.tpl")}"
vars {
bastion_ip = "${var.bastion_host}"
controller_hosts = "${join("\n", data.template_file.controller_ansible.*.rendered)}"
worker_hosts = "${join("\n", data.template_file.worker_ansible.*.rendered)}"
}
}
resource "local_file" "ansible_inventory" {
content = "${data.template_file.ansible_inventory.rendered}"
filename = "${path.module}/output/ansible_inventory"
}