-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.tf
126 lines (115 loc) · 4.61 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
# Add public key
resource "openstack_compute_keypair_v2" "keypair" {
name = "${var.cluster_prefix}-keypair"
public_key = "${file(var.ssh_key_pub)}"
}
# Create security group
module "secgroup" {
source = "modules/secgroup"
name_prefix = "${var.cluster_prefix}"
allowed_ingress_tcp = "${var.allowed_ingress_tcp}"
allowed_ingress_udp = "${var.allowed_ingress_udp}"
}
# Create network
module "network" {
source = "modules/network"
name_prefix = "${var.cluster_prefix}"
external_network_id = "${var.external_network_id}"
}
# Create master node
module "master" {
source = "modules/node"
count = "${var.master_count}"
name_prefix = "${var.cluster_prefix}-master"
flavor_name = "${var.master_flavor_name}"
image_name = "${var.image_name}"
network_name = "${module.network.network_name}"
secgroup_name = "${module.secgroup.secgroup_name}"
floating_ip_pool = "${var.floating_ip_pool}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
os_ssh_keypair = "${openstack_compute_keypair_v2.keypair.name}"
ssh_bastion_host = "${element(module.edge.public_ip_list,0)}"
docker_version = "${var.docker_version}"
assign_floating_ip = "${var.master_assign_floating_ip}"
role = ["controlplane", "etcd"]
labels = {
node_type = "master"
}
}
# Create service nodes
module "service" {
source = "modules/node"
count = "${var.service_count}"
name_prefix = "${var.cluster_prefix}-service"
flavor_name = "${var.service_flavor_name}"
image_name = "${var.image_name}"
network_name = "${module.network.network_name}"
secgroup_name = "${module.secgroup.secgroup_name}"
floating_ip_pool = "${var.floating_ip_pool}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
os_ssh_keypair = "${openstack_compute_keypair_v2.keypair.name}"
ssh_bastion_host = "${element(module.edge.public_ip_list,0)}"
docker_version = "${var.docker_version}"
assign_floating_ip = "${var.service_assign_floating_ip}"
role = ["worker"]
labels = {
node_type = "service"
}
}
# Create edge nodes
module "edge" {
source = "modules/node"
count = "${var.edge_count}"
name_prefix = "${var.cluster_prefix}-edge"
flavor_name = "${var.edge_flavor_name}"
image_name = "${var.image_name}"
network_name = "${module.network.network_name}"
secgroup_name = "${module.secgroup.secgroup_name}"
floating_ip_pool = "${var.floating_ip_pool}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
os_ssh_keypair = "${openstack_compute_keypair_v2.keypair.name}"
docker_version = "${var.docker_version}"
assign_floating_ip = "${var.edge_assign_floating_ip}"
role = ["worker"]
labels = {
node_type = "edge"
}
}
# Compute dynamic dependencies for RKE provisioning step
locals {
rke_cluster_deps = [
"${join(",",module.master.prepare_nodes_id_list)}", # Master stuff ...
"${join(",",module.service.prepare_nodes_id_list)}", # Service stuff ...
"${join(",",module.edge.prepare_nodes_id_list)}", # Edge stuff ...
"${join(",",module.edge.associate_floating_ip_id_list)}",
"${join(",",module.secgroup.rule_id_list)}", # Other stuff ...
"${module.network.interface_id}",
]
}
# Provision Kubernetes
module "rke" {
source = "modules/rke"
rke_cluster_deps = "${local.rke_cluster_deps}"
node_mappings = "${concat(module.master.node_mappings,module.service.node_mappings,module.edge.node_mappings)}"
ssh_bastion_host = "${element(module.edge.public_ip_list,0)}"
ssh_user = "${var.ssh_user}"
ssh_key = "${var.ssh_key}"
kubeapi_sans_list = "${module.edge.public_ip_list}"
ignore_docker_version = "${var.ignore_docker_version}"
write_kube_config_cluster = "${var.write_kube_config_cluster}"
write_cluster_yaml = "${var.write_cluster_yaml}"
}
# Create DNS records if required
module "cloudflare" {
source = "modules/cloudflare"
cloudflare_enable = "${var.cloudflare_enable}"
cloudflare_domain = "${var.cloudflare_domain}"
cloudflare_record_name = "${var.cloudflare_record_name}"
dns_value_list = "${module.edge.public_ip_list}"
dns_record_count = "${var.edge_count}"
cloudflare_email = "${var.cloudflare_email}"
cloudflare_api_key = "${var.cloudflare_api_key}"
}