-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
166 lines (154 loc) · 4.68 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
provider "azurerm" {
features {}
environment = var.azure_environment
}
resource "random_string" "random" {
length = 6
special = false
lower = true
min_upper = 2
min_numeric = 2
}
locals {
cluster_name = var.cluster_name == "" ? random_string.random.result : var.cluster_name
}
module "vnet" {
source = "./modules/vnet"
location = var.azure_region
cluster_name = local.cluster_name
host_cidr = var.vnet_cidr
subnet_cidr = var.address_space
virtual_network_name = var.vnet_name
tags = var.tags
}
module "common" {
source = "./modules/common"
location = var.azure_region
cluster_name = local.cluster_name
rg = module.vnet.rg
vnet_id = module.vnet.id
subnet_id = module.vnet.subnet_id
tags = var.tags
}
module "masters" {
source = "./modules/master"
master_count = var.master_count
vnet_id = module.vnet.id
rg = module.vnet.rg
cluster_name = local.cluster_name
location = var.azure_region
subnet_id = module.vnet.subnet_id
ssh_key = module.common.ssh_key
image = var.image_ubuntu1804
master_type = var.master_type
tags = var.tags
fault_domain_count = var.fault_domain_count
update_domain_count = var.update_domain_count
}
module "workers" {
count = var.worker_count > 0 ? 1 : 0
source = "./modules/worker"
worker_count = var.worker_count
vnet_id = module.vnet.id
rg = module.vnet.rg
cluster_name = local.cluster_name
location = var.azure_region
subnet_id = module.vnet.subnet_id
ssh_key = module.common.ssh_key
image = var.image_ubuntu1804
worker_type = var.worker_type
tags = var.tags
fault_domain_count = var.fault_domain_count
update_domain_count = var.update_domain_count
}
module "windows_workers" {
count = var.windows_worker_count > 0 ? 1 : 0
source = "./modules/windows_worker"
worker_count = var.windows_worker_count
vnet_id = module.vnet.id
rg = module.vnet.rg
cluster_name = local.cluster_name
location = var.azure_region
subnet_id = module.vnet.subnet_id
ssh_key = module.common.ssh_key
image = var.image_windows2019
worker_type = var.worker_type
username = var.windows_admin_username
tags = var.tags
fault_domain_count = var.fault_domain_count
update_domain_count = var.update_domain_count
}
locals {
managers = [
for ip in module.masters.public_ips : {
ssh = {
address = ip
user = "ubuntu"
keyPath = "./ssh_keys/${local.cluster_name}.pem"
}
privateInterface = "eth0"
role = "manager"
}
]
workers = var.worker_count > 0 ? [
for ip in module.workers[0].public_ips : {
ssh = {
address = ip
user = "ubuntu"
keyPath = "./ssh_keys/${local.cluster_name}.pem"
}
privateInterface = "eth0"
role = "worker"
}
] : []
windows_workers = var.windows_worker_count > 0 ? [
for ip in module.windows_workers[0].public_ips : {
winRM = {
address = ip
user = var.windows_admin_username
password = module.windows_workers[0].windows_password
useHTTPS = true
insecure = true
}
privateInterface = "Ethernet"
role = "worker"
}
] : []
}
locals {
launchpad_tmpl = {
apiVersion = "launchpad.mirantis.com/mke/v1.4"
kind = "mke"
metadata = {
name = local.cluster_name
}
spec = {
mcr = {
channel = "stable"
installURLLinux = "https://get.mirantis.com/"
installURLWindows = "https://get.mirantis.com/install.ps1"
repoURL = "https://repos.mirantis.com"
version = var.mcr_version
}
mke = {
adminUsername = "admin"
adminPassword = var.admin_password
version = var.mke_version
installFlags : [
"--default-node-orchestrator=kubernetes",
"--san=${module.masters.lb_dns_name}",
]
}
hosts = concat(local.managers, local.workers, local.windows_workers)
}
}
}
output "mke_cluster" {
value = yamlencode(local.launchpad_tmpl)
}
output "loadbalancers" {
value = {
MasterLB = module.masters.lb_dns_name
WorkersLB = var.worker_count > 0 ? module.workers[0].lb_dns_name : ""
}
}