-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
189 lines (161 loc) · 6.44 KB
/
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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# instance the provider
provider "libvirt" {
uri = var.provider_uri
}
provider "rke" {
log_file = "rke_debug.log"
}
provider "kubernetes" {
host = module.rancher.api_server_url
client_certificate = module.rancher.client_cert
client_key = module.rancher.client_key
cluster_ca_certificate = module.rancher.ca_crt
}
provider "helm" {
kubernetes {
host = module.rancher.api_server_url
client_certificate = module.rancher.client_cert
client_key = module.rancher.client_key
cluster_ca_certificate = module.rancher.ca_crt
}
}
# ---------------------------------------------------------------------------------------------------------------------
# CREATE SSH KEYS
# ---------------------------------------------------------------------------------------------------------------------
resource "tls_private_key" "id" {
algorithm = "RSA"
rsa_bits = "4096"
}
# Store the id private key in a file.
resource "local_file" "id_rsa" {
depends_on = [tls_private_key.id]
filename = "modules/keys/id_rsa"
file_permission = "0600"
sensitive_content = tls_private_key.id.private_key_pem
}
# Store the id public key in a file.
resource "local_file" "id_rsa_pub" {
content = tls_private_key.id.public_key_openssh
filename = "modules/keys/id_rsa.pub"
depends_on = [tls_private_key.id]
}
# ---------------------------------------------------------------------------------------------------------------------
# Spin up Master nodes
# ---------------------------------------------------------------------------------------------------------------------
module "master" {
depends_on = [tls_private_key.id]
count = length(var.masterHosts)
source = "./modules/master/"
machine_name = var.masterHosts[count.index].hostname
mac_address = var.masterHosts[count.index].mac
ip_address = var.masterHosts[count.index].ip
cluster_name = var.cluster_name
user_data_path = "${path.module}/cloud_init.cfg"
storage_pool = var.storage_pool
cpu = var.master_cpu
memory = var.master_memory
ssh_key_file = tls_private_key.id.private_key_pem
public_key = tls_private_key.id.public_key_openssh
salt_master_address = var.workstation.ip
registry_ip = var.registry_ip
registry_fqdn = var.registry_fqdn
registry_hostname = var.registry_hostname
}
# ---------------------------------------------------------------------------------------------------------------------
# Spin up Worker nodes
# ---------------------------------------------------------------------------------------------------------------------
module "worker" {
depends_on = [tls_private_key.id]
count = length(var.workerHosts)
source = "./modules/worker/"
machine_name = var.workerHosts[count.index].hostname
mac_address = var.workerHosts[count.index].mac
ip_address = var.workerHosts[count.index].ip
cluster_name = var.cluster_name
user_data_path = "${path.module}/cloud_init.cfg"
storage_pool = var.storage_pool
cpu = var.worker_cpu
memory = var.worker_memory
ssh_key_file = tls_private_key.id.private_key_pem
public_key = tls_private_key.id.public_key_openssh
salt_master_address = var.workstation.ip
registry_ip = var.registry_ip
registry_fqdn = var.registry_fqdn
registry_hostname = var.registry_hostname
}
# ---------------------------------------------------------------------------------------------------------------------
# Deploy RKE
# ---------------------------------------------------------------------------------------------------------------------
locals {
masterList = flatten([
for host in module.master : {
ip = host.ip
hostname = host.hostname
roles = host.roles
ssh_key = tls_private_key.id.private_key_pem
user = host.user
}
])
workerList = flatten([
for host in module.worker : {
ip = host.ip
hostname = host.hostname
roles = host.roles
ssh_key = tls_private_key.id.private_key_pem
user = host.user
}
])
}
module "rancher" {
depends_on = [module.master, module.worker, local.masterList, local.workerList]
source = "./modules/rke/"
rke_nodes = concat(local.masterList, local.workerList)
rke = {
cluster_name = "rancher_test"
dind = false
kubernetes_version = var.rke_Version
}
}
// Write kubeconfig to Terraform host
resource "local_file" "kubeconfig" {
content = module.rancher.kubeconfig
filename = "modules/k8s/kubeconfig"
depends_on = [module.rancher]
}
# ---------------------------------------------------------------------------------------------------------------------
# Prepare Kubernetes for SAP DI Deployment
# ---------------------------------------------------------------------------------------------------------------------
module "kubernetes" {
depends_on = [module.rancher]
source = "./modules/k8s"
namespace = var.k8s_namespace
ceph_admin_secret = var.ceph_admin_secret
ceph_user_secret = var.ceph_user_secret
}
module "helm" {
depends_on = [module.kubernetes]
source = "./modules/rancher"
rancherUI_address = var.rancherUI_address
rancherUI_version = var.rancherUI_version
cert_manager_version = var.cert_manager_version
}
# ---------------------------------------------------------------------------------------------------------------------
# Spin up Workstation
# ---------------------------------------------------------------------------------------------------------------------
module "workstation" {
depends_on = [module.rancher]
source = "./modules/workstation/"
machine_name = var.workstation.hostname
ip_address = var.workstation.ip
cluster_name = var.cluster_name
user_data_path = "${path.module}/modules/workstation/cloud_init.cfg"
storage_pool = var.storage_pool
cpu = var.workstation.cpu
memory = var.workstation.memory
ssh_key_file = tls_private_key.id.private_key_pem
public_key = tls_private_key.id.public_key_openssh
kubeconfig = module.rancher.kubeconfig
registry_ip = var.registry_ip
registry_fqdn = var.registry_fqdn
registry_hostname = var.registry_hostname
}