-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
55 lines (45 loc) · 1.08 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
# Firewall settings
resource "google_compute_firewall" "firewall_mongo" {
name = "allow-mongo-default"
network = "default"
allow {
protocol = "tcp"
ports = ["${var.db_port}"]
}
# tag - from connection
source_tags = ["reddit-app"]
# tag - to connection
target_tags = ["reddit-db"]
}
# DB instance settings
resource "google_compute_instance" "db" {
name = "reddit-db"
machine_type = "g1-small"
zone = "${var.zone}"
tags = ["reddit-db"]
boot_disk {
initialize_params {
image = "${var.disk_image_db}"
}
}
metadata {
ssh-keys = "appuser:${file(var.public_key_path)}"
}
network_interface {
network = "default"
access_config = {}
}
connection {
type = "ssh"
user = "appuser"
agent = false
private_key = "${file(var.private_key_path)}"
}
provisioner "remote-exec" {
inline = [
"sudo sed -i 's/127.0.0.1/0.0.0.0/' /etc/mongod.conf",
"sudo sed -i 's/27017/${var.db_port}/' /etc/mongod.conf",
"sudo systemctl restart mongod",
]
}
}