-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.tf
207 lines (169 loc) · 7.03 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# force local ignition provider binary
# provider "ignition" {
# version = "0.0.0"
# }
locals {
cluster_domain = "${var.cluster_id}.${var.base_domain}"
bootstrap_fqdns = ["bootstrap-0.${local.cluster_domain}"]
control_plane_fqdns = [for idx in range(var.control_plane_count) : "control-plane-${idx}.${local.cluster_domain}"]
compute_fqdns = [for idx in range(var.compute_count) : "compute-${idx}.${local.cluster_domain}"]
storage_fqdns = [for idx in range(var.storage_count) : "storage-${idx}.${local.cluster_domain}"]
}
provider "vsphere" {
user = var.vsphere_user
password = var.vsphere_password
vsphere_server = var.vsphere_server
allow_unverified_ssl = true
}
data "vsphere_datacenter" "dc" {
name = var.vsphere_datacenter
}
data "vsphere_compute_cluster" "compute_cluster" {
name = var.vsphere_cluster
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_datastore" "datastore" {
name = var.vsphere_datastore
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_network" "network" {
name = var.vm_network
datacenter_id = data.vsphere_datacenter.dc.id
}
data "vsphere_virtual_machine" "template" {
name = var.vm_template
datacenter_id = data.vsphere_datacenter.dc.id
}
resource "vsphere_resource_pool" "resource_pool" {
name = var.cluster_id
parent_resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
}
resource "vsphere_folder" "folder" {
path = var.cluster_id
type = "vm"
datacenter_id = data.vsphere_datacenter.dc.id
}
resource "tls_private_key" "installkey" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "local_file" "write_private_key" {
content = tls_private_key.installkey.private_key_pem
filename = "${path.root}/installer/${var.cluster_id}/sshkeys/openshift_rsa"
file_permission = 0600
}
resource "local_file" "write_public_key" {
content = tls_private_key.installkey.public_key_openssh
filename = "${path.root}/installer/${var.cluster_id}/sshkeys/openshift_rsa.pub"
file_permission = 0600
}
module "ignition" {
source = "./ignition"
ssh_public_key = chomp(tls_private_key.installkey.public_key_openssh)
base_domain = var.base_domain
cluster_id = var.cluster_id
cluster_cidr = var.openshift_cluster_cidr
cluster_hostprefix = var.openshift_host_prefix
cluster_servicecidr = var.openshift_service_cidr
machine_cidr = var.machine_cidr
vsphere_server = var.vsphere_server
vsphere_username = var.vsphere_user
vsphere_password = var.vsphere_password
vsphere_datacenter = var.vsphere_datacenter
vsphere_datastore = var.vsphere_datastore
vsphere_cluster = var.vsphere_cluster
vsphere_network = var.vm_network
api_vip = var.create_openshift_vips ? var.openshift_api_virtualip : ""
ingress_vip = var.create_openshift_vips ? var.openshift_ingress_virtualip : ""
pull_secret = var.openshift_pull_secret
openshift_version = var.openshift_version
total_node_count = var.compute_count + var.storage_count
}
module "bootstrap" {
source = "./vm"
ignition = module.ignition.bootstrap_ignition
hostnames_ip_addresses = zipmap(
local.bootstrap_fqdns,
[var.bootstrap_ip_address]
)
resource_pool_id = vsphere_resource_pool.resource_pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.dc.id
network_id = data.vsphere_network.network.id
folder_id = vsphere_folder.folder.path
guest_id = data.vsphere_virtual_machine.template.guest_id
template_uuid = data.vsphere_virtual_machine.template.id
disk_thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
cluster_domain = local.cluster_domain
machine_cidr = var.machine_cidr
num_cpus = 2
memory = 8192
dns_addresses = var.vm_dns_addresses
vm_gateway = var.vm_gateway == null ? cidrhost(var.machine_cidr, 1) : var.vm_gateway
}
module "control_plane_vm" {
source = "./vm"
hostnames_ip_addresses = zipmap(
local.control_plane_fqdns,
var.control_plane_ip_addresses
)
ignition = module.ignition.master_ignition
resource_pool_id = vsphere_resource_pool.resource_pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.dc.id
network_id = data.vsphere_network.network.id
folder_id = vsphere_folder.folder.path
guest_id = data.vsphere_virtual_machine.template.guest_id
template_uuid = data.vsphere_virtual_machine.template.id
disk_thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
cluster_domain = local.cluster_domain
machine_cidr = var.machine_cidr
num_cpus = var.control_plane_num_cpus
memory = var.control_plane_memory
dns_addresses = var.vm_dns_addresses
vm_gateway = var.vm_gateway == null ? cidrhost(var.machine_cidr, 1) : var.vm_gateway
}
module "compute_vm" {
source = "./vm"
hostnames_ip_addresses = zipmap(
local.compute_fqdns,
var.compute_ip_addresses
)
ignition = module.ignition.worker_ignition
resource_pool_id = vsphere_resource_pool.resource_pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.dc.id
network_id = data.vsphere_network.network.id
folder_id = vsphere_folder.folder.path
guest_id = data.vsphere_virtual_machine.template.guest_id
template_uuid = data.vsphere_virtual_machine.template.id
disk_thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
cluster_domain = local.cluster_domain
machine_cidr = var.machine_cidr
num_cpus = var.compute_num_cpus
memory = var.compute_memory
dns_addresses = var.vm_dns_addresses
vm_gateway = var.vm_gateway == null ? cidrhost(var.machine_cidr, 1) : var.vm_gateway
}
module "storage_vm" {
source = "./vm"
hostnames_ip_addresses = zipmap(
local.storage_fqdns,
var.storage_ip_addresses
)
ignition = module.ignition.worker_ignition
resource_pool_id = vsphere_resource_pool.resource_pool.id
datastore_id = data.vsphere_datastore.datastore.id
datacenter_id = data.vsphere_datacenter.dc.id
network_id = data.vsphere_network.network.id
folder_id = vsphere_folder.folder.path
guest_id = data.vsphere_virtual_machine.template.guest_id
template_uuid = data.vsphere_virtual_machine.template.id
disk_thin_provisioned = data.vsphere_virtual_machine.template.disks[0].thin_provisioned
cluster_domain = local.cluster_domain
machine_cidr = var.machine_cidr
num_cpus = var.storage_num_cpus
memory = var.storage_memory
dns_addresses = var.vm_dns_addresses
vm_gateway = var.vm_gateway == null ? cidrhost(var.machine_cidr, 1) : var.vm_gateway
}