forked from cmndrsp0ck/galera-tf-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
68 lines (59 loc) · 2.32 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
locals {
default_db_node_size = "${basename(path.root) == "staging" ? "1gb" : "2gb"}"
}
# Creating the Galera cluster nodes
resource "digitalocean_droplet" "galera_cluster_node" {
count = "${var.db_node_count}"
image = "${var.image_slug}"
name = "${basename(path.root)}-${var.project}-database-${format("%02d", count.index + 1)}"
region = "${var.region}"
size = "${var.db_node_size == "" ? local.default_db_node_size : var.db_node_size}"
private_networking = true
ssh_keys = ["${split(",",var.keys)}"]
tags = ["${digitalocean_tag.env_tag.id}", "${digitalocean_tag.project_tag.id}", "${digitalocean_tag.resource_role1.id}", "${digitalocean_tag.add_tag.id}"]
user_data = "${data.template_file.user_data.rendered}"
lifecycle {
# TODO: switch this to true after testing
prevent_destroy = false
}
connection {
user = "root"
type = "ssh"
private_key = "${var.private_key_path}"
timeout = "2m"
}
}
# Creating the Galera load balancer nodes
resource "digitalocean_droplet" "galera_loadbalancer" {
count = 2
image = "${var.image_slug}"
name = "${basename(path.root)}-${var.project}-db-loadbalancer-${format("%02d", count.index + 1)}"
region = "${var.region}"
size = "${var.lb_size}"
private_networking = true
ssh_keys = ["${split(",",var.keys)}"]
tags = ["${digitalocean_tag.env_tag.id}", "${digitalocean_tag.project_tag.id}", "${digitalocean_tag.resource_role2.id}", "${digitalocean_tag.add_tag.id}"]
user_data = "${data.template_file.user_data.rendered}"
lifecycle {
# TODO: switch this to true after testing
prevent_destroy = false
}
connection {
user = "root"
type = "ssh"
private_key = "${var.private_key_path}"
timeout = "2m"
}
}
# Passing in user-data to set up Ansible user for configuration
data "template_file" "user_data" {
template = "${file("${path.root}/config/cloud-config.yaml")}"
vars {
public_key = "${var.public_key}"
ansible_user = "${var.ansible_user}"
}
}
resource "digitalocean_floating_ip" "ha_db_fip" {
region = "${var.region}"
droplet_id = "${digitalocean_droplet.galera_loadbalancer.0.id}"
}