-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf.old
145 lines (124 loc) · 4.57 KB
/
main.tf.old
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
variable k3sversion {}
variable "master1_ip" {}
variable "username" {}
#variable "master_ip" {}
variable "password" {}
variable "sshkeyfile" {}
variable "master2_ip" {}
variable "master3_ip" {}
variable "token" {}
variable "tlssan" {}
variable token_file {}
#variable user_data {}
#variable content {}
# variable "nodetoken" {
# type = string
# }
# variable "timezone" {}
# variable "new_hostname" {}
# variable "private_key_name" {
# type = string
# description = "File path of private key."
# default = "id_rsa"
# }
# variable "key_path"{
# type = string
# description = "Dir path of private key."
# default = "/home/stoyan/.ssh/it"
# }
resource "null_resource" "master1_ip" {
connection {
type = "ssh"
user = "${var.username}"
password = "${var.password}"
# private_key = "${file("${var.key_path}/${var.private_key_name}")}"
# # The connection will use the local SSH agent for authentication.
agent = false
timeout = "1m"
host = "${var.master1_ip}"
}
provisioner "remote-exec" {
# INSTALL K3S MASTER
inline=[
"curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3sversion} INSTALL_K3S_EXEC='--cluster-init --disable traefik --disable local-storage --tls-san=${var.tlssan}' sh -s - server",
]
}
}
resource "null_resource" "retrieve_token" {
provisioner "local-exec" {
command = "ssh ${var.username}@${var.master1_ip} -i ${var.sshkeyfile} 'sudo cat /var/lib/rancher/k3s/server/token' > rem_token.txt"
}
depends_on = [null_resource.master1_ip]
}
data "local_file" "token_file" {
filename = "${path.module}/rem_token.txt"
# depends_on = [null_resource.retrieve_token]
}
# output "Token" {
# value = data.local_file.token_file.content
# }
# resource "null_resource" "copy_token" {
# provisioner "local-exec" {
# # command = "export K3S_TOKEN = $(cat remote_token.txt)"
# command ="export K3S_TOKEN='$(cat remote_token.txt)'"
# }
# depends_on = [null_resource.retrieve_token]
# }
resource "null_resource" "master2_ip" {
connection {
type = "ssh"
user = "${var.username}"
password = "${var.password}"
# private_key = "${file("${var.key_path}/${var.private_key_name}")}"
# # The connection will use the local SSH agent for authentication.
agent = false
timeout = "1m"
host = "${var.master2_ip}"
}
# provisioner "remote-exec" {
# # INSTALL K3S MASTER 2
# inline=[
# "curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3sversion}",
# "K3S_TOKEN='${data.local_file.token_file.content }'",
# "K3S_URL=https://${var.master1_ip}:6443 INSTALL_K3S_EXEC='server --cluster-init --disable traefik --disable local-storage -tls-san=${var.tlssan}' sh -s",
# ]
# }
# depends_on = [null_resource.retrieve_token]
# #depends_on = [null_resource.master1_ip]
# }
provisioner "remote-exec" {
inline = [
#"export K3S_TOKEN=$(cat ${path.module}/remote_token.txt)",${data.local_file.token_file.content}
"curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3sversion} K3S_TOKEN=${data.local_file.token_file.content} K3S_URL=https://${var.master1_ip}:6443 sh -s - server --cluster-init --disable traefik --disable local-storage -tls-san=${var.tlssan}",
]
}
depends_on = [null_resource.retrieve_token]
#depends_on = [null_resource.master1_ip]
}
resource "null_resource" "master3_ip" {
connection {
type = "ssh"
user = "${var.username}"
password = "${var.password}"
# private_key = "${file("${var.key_path}/${var.private_key_name}")}"
# # The connection will use the local SSH agent for authentication.
agent = false
timeout = "1m"
host = "${var.master3_ip}"
}
# provisioner "remote-exec" {
# # INSTALL K3S MASTER 2
# inline=[
# "curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3sversion} K3S_TOKEN=${data.local_file.token_file.content} K3S_URL=https://${var.master1_ip}:6443 INSTALL_K3S_EXEC='server --cluster-init --disable traefik --disable local-storage -tls-san=${var.tlssan}' sh -s",
# ]
# }
# depends_on = [null_resource.master2_ip]
# }
provisioner "remote-exec" {
inline = [
#"export K3S_TOKEN=$(cat ${path.module}/remote_token.txt)",
"curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${var.k3sversion} K3S_TOKEN=${data.local_file.token_file.content} K3S_URL=https://${var.master1_ip}:6443 INSTALL_K3S_EXEC='server --cluster-init --disable traefik --disable local-storage -tls-san=${var.tlssan}' sh -s",
]
}
depends_on = [null_resource.master2_ip]
}