-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.tf
97 lines (85 loc) · 2.62 KB
/
db.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
###################################
# Create port
###################################
resource "openstack_networking_port_v2" "port_db" {
name = "node-db"
network_id = "${openstack_networking_network_v2.network_1.id}"
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
}
}
###################################
# Create Volume/Disk
###################################
resource "openstack_blockstorage_volume_v3" "volume_db" {
name = "volume-for-db"
size = "${var.hdd_size}"
image_id = "${data.openstack_images_image_v2.ubuntu.id}"
volume_type = "${var.volume_type}"
availability_zone = "${var.az_zone}"
enable_online_resize = true
lifecycle {
ignore_changes = ["image_id"]
}
}
###################################
# Create Server
###################################
resource "openstack_compute_instance_v2" "instance_db" {
name = "db"
flavor_id = "${data.openstack_compute_flavor_v2.flavor_1.id}"
key_pair = "${openstack_compute_keypair_v2.terraform_key.id}"
availability_zone = "${var.az_zone}"
network {
port = "${openstack_networking_port_v2.port_db.id}"
}
block_device {
uuid = "${openstack_blockstorage_volume_v3.volume_db.id}"
source_type = "volume"
destination_type = "volume"
boot_index = 0
}
vendor_options {
ignore_resize_confirmation = true
}
metadata = {
consul = "server"
}
provisioner "file" {
source = "${path.module}/scripts/setup_db.sh"
destination = "/tmp/setup_db.sh"
connection {
type = "ssh"
host = "${openstack_networking_floatingip_v2.floatingip_db.address}"
user = "root"
# private_key = "${file("~/.ssh/id_rsa")}"
#agent = true
}
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/setup_db.sh",
"/tmp/setup_db.sh",
]
connection {
type = "ssh"
host = "${openstack_networking_floatingip_v2.floatingip_db.address}"
user = "root"
# private_key = "${file("~/.ssh/id_rsa")}"
#agent = true
}
}
}
###################################
# Create floating IP
###################################
resource "openstack_networking_floatingip_v2" "floatingip_db" {
pool = "external-network"
}
###################################
# Link floating IP to internal IP
###################################
resource "openstack_networking_floatingip_associate_v2" "association_1" {
port_id = "${openstack_networking_port_v2.port_db.id}"
floating_ip = "${openstack_networking_floatingip_v2.floatingip_db.address}"
}