-
Notifications
You must be signed in to change notification settings - Fork 0
/
master_hosts.tf
114 lines (100 loc) · 3.17 KB
/
master_hosts.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
data "template_file" "master_config" {
template = "${file("files/init.tpl")}"
count = "${var.openshift_masters}"
vars {
hostname = "${format("master%02d", count.index + 1)}"
fqdn = "${format("master%02d", count.index + 1)}.${var.domain_name}"
root_size = "40G"
}
}
resource "openstack_blockstorage_volume_v2" "master" {
region = "RegionOne"
name = "${format("master%02d", count.index + 1)}"
image_id = "${data.openstack_images_image_v2.atomic.id}"
description = "OpenShift Master volume"
size = 50
count = "${var.openshift_masters}"
timeouts {
create = "60m"
delete = "2h"
}
}
#resource "openstack_blockstorage_volume_v2" "master_data" {
# region = "RegionOne"
# name = "${format("master%02d_data", count.index + 1)}"
# description = "OpenShift Master data"
# size = 50
# count = "${var.openshift_masters}"
#}
#resource "openstack_compute_volume_attach_v2" "master_data" {
# instance_id = "${element(openstack_compute_instance_v2.master.*.id, count.index)}"
# volume_id = "${element(openstack_blockstorage_volume_v2.master_data.*.id, count.index)}"
# count = "${var.openshift_masters}"
#}
resource "openstack_compute_instance_v2" "master" {
name = "${format("master%02d", count.index + 1)}.${var.domain_name}"
flavor_name = "${var.master_type}"
key_pair = "${openstack_compute_keypair_v2.ssh-keypair.name}"
user_data = "${element(data.template_file.master_config.*.rendered, count.index)}"
count = "${var.openshift_masters}"
block_device {
uuid = "${element(openstack_blockstorage_volume_v2.master.*.id, count.index)}"
source_type = "volume"
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}
network {
name = "${var.network_name}"
}
security_groups = [
"${var.local_ssh_sec_group}",
"${var.local_consul_sec_group}",
"${openstack_networking_secgroup_v2.openshift.name}"
]
connection {
user = "centos"
private_key = "${file(var.private_key_file)}"
}
provisioner "remote-exec" {
inline = [
"sudo rpm-ostree install unzip",
"sudo systemctl reboot"
]
}
provisioner "file" {
content = "${data.template_file.setup_consul.rendered}"
destination = "/tmp/install_consul.sh"
}
# provisioner "file" {
# source = "files/attach_data_vol.sh"
# destination = "/tmp/attach_data_vol.sh"
# }
provisioner "remote-exec" {
inline = [
"sudo chmod a+x /tmp/install_consul.sh",
"sudo /tmp/install_consul.sh"
]
}
}
#resource "null_resource" "master" {
# triggers {
# instance_id = "${element(openstack_compute_instance_v2.master.*.id, count.index)}"
# vol_attachment = "${element(openstack_compute_volume_attach_v2.master_data.*.id, count.index)}"
# }
# count = "${var.openshift_masters}"
#
# connection {
# host = "${element(openstack_compute_instance_v2.master.*.access_ip_v4, count.index)}"
# user = "centos"
# private_key = "${file(var.private_key_file)}"
# }
#
# provisioner "remote-exec" {
# inline = [
# "sudo lsblk",
# "sudo chmod a+x /tmp/attach_data_vol.sh",
# "sudo /tmp/attach_data_vol.sh"
# ]
# }
#}