-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s.tf
69 lines (56 loc) · 2.11 KB
/
k8s.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
terraform {
required_providers {
openstack = ">= 1.22.0"
local = ">= 1.3.0"
}
}
# Create a single master node and floating IP
resource "openstack_compute_instance_v2" "k8s-master" {
count = "${var.master_count}"
name = "k8s-master-${count.index}"
image_id = "${var.image_id}"
flavor_name = "${var.image_flavor}"
key_pair = "${var.key_pair}"
security_groups = "${split(",", var.security_groups_master)}"
network {
name = "${var.network_name}"
}
}
resource "openstack_compute_floatingip_associate_v2" "k8s-master-ip" {
count = "${var.master_count}"
floating_ip = "${element(openstack_networking_floatingip_v2.k8s-master-ip.*.address, count.index)}"
instance_id = "${element(openstack_compute_instance_v2.k8s-master.*.id, count.index)}"
}
resource "openstack_networking_floatingip_v2" "k8s-master-ip" {
count = "${var.master_count}"
pool = "${var.floating_ip_pool}"
}
# Create desired number of k8s nodes
resource "openstack_compute_instance_v2" "k8s-node" {
count = "${var.node_count}"
name = "k8s-node-${count.index}"
image_id = "${var.image_id}"
flavor_name = "${var.image_flavor}"
key_pair = "${var.key_pair}"
security_groups = "${split(",", var.security_groups_slave)}"
network {
name = "${var.network_name}"
}
}
resource "local_file" "test" {
filename = "${path.module}/${var.inventory_path}/hosts.ini"
content = <<EOF
bastion ansible_host=142.1.177.99 ansible_user=ubuntu
${join("\n",formatlist("%s ansible_host=%s", openstack_compute_instance_v2.k8s-master.*.name, openstack_compute_instance_v2.k8s-master.*.network.0.fixed_ip_v4))}
[kube-master]
${join("\n",formatlist("%s", openstack_compute_instance_v2.k8s-master.*.name))}
[etcd]
${join("\n",formatlist("%s", openstack_compute_instance_v2.k8s-master.*.name))}
${element(openstack_compute_instance_v2.k8s-node.*.name, 0)}
[kube-node]
${join("\n",formatlist("%s ansible_host=%s", openstack_compute_instance_v2.k8s-node.*.name, openstack_compute_instance_v2.k8s-node.*.network.0.fixed_ip_v4))}
[k8s-cluster:children]
kube-node
kube-master
EOF
}