-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
79 lines (72 loc) · 2.47 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
resource "random_string" "postgres_password" {
length = 20
special = false
}
locals {
postgres_password = var.postgres_password != "" ? var.postgres_password : random_string.postgres_password.result
postgres_params = "-c ssl=on -c ssl_cert_file=/opt/pg.pem -c ssl_key_file=/opt/pg.key ${var.postgres_params}"
block_devices = var.image_source.volume_id != "" ? [{
uuid = var.image_source.volume_id
source_type = "volume"
boot_index = 0
destination_type = "volume"
delete_on_termination = false
}] : []
}
data "template_cloudinit_config" "postgres_config" {
gzip = true
base64_encode = true
part {
content_type = "text/cloud-config"
content = templatefile(
"${path.module}/templates/cloud_config.yaml",
{
postgres_orchestration = templatefile(
"${path.module}/templates/docker-compose.yml",
{
image = var.postgres_image
params = local.postgres_params
data = var.postgres_data
user = var.postgres_user
password = local.postgres_password
database = var.postgres_database
}
)
tls_key = tls_private_key.key.private_key_pem
tls_certificate = "${tls_locally_signed_cert.certificate.cert_pem}\n${var.ca.certificate}"
postgres_image = var.postgres_image
}
)
}
}
resource "openstack_networking_port_v2" "postgres" {
name = var.name
network_id = var.network_id
security_group_ids = [openstack_networking_secgroup_v2.postgres_server.id]
admin_state_up = true
}
resource "openstack_compute_instance_v2" "postgres" {
name = var.name
image_id = var.image_source.image_id != "" ? var.image_source.image_id : null
flavor_id = var.flavor_id
key_pair = var.keypair_name
user_data = data.template_cloudinit_config.postgres_config.rendered
network {
port = openstack_networking_port_v2.postgres.id
}
dynamic "block_device" {
for_each = local.block_devices
content {
uuid = block_device.value["uuid"]
source_type = block_device.value["source_type"]
boot_index = block_device.value["boot_index"]
destination_type = block_device.value["destination_type"]
delete_on_termination = block_device.value["delete_on_termination"]
}
}
lifecycle {
ignore_changes = [
user_data,
]
}
}