-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
78 lines (65 loc) · 1.93 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
provider "digitalocean" {
token = "${var.do_token}"
}
data "template_file" "cca-docker-compose-file" {
template = "${file("${path.module}/.deployment/docker-compose.yml.tpl")}"
vars {
admin_password = "${var.admin_password}"
}
}
data "template_file" "cca-nginx-file" {
template = "${file("${path.module}/.deployment/nginx.conf.tpl")}"
vars {
allow_application_ip_block = "${join("\n", formatlist("allow %s;", var.application_allowed_ip_list))}"
allow_admin_ip_block = "${join("\n", formatlist("allow %s;", var.admin_allowed_ip_list))}"
}
}
resource "digitalocean_droplet" "application" {
name = "cca-application-adobe2018"
image = "${var.droplet_image}"
region = "${var.droplet_region}"
size = "${var.droplet_size}"
private_networking = true
ssh_keys = ["${var.ssh_key_fingerprint}"]
# prepare folder structure
provisioner "remote-exec" {
inline = [
"mkdir -p /cca/app",
"echo '${data.template_file.cca-docker-compose-file.rendered}' > /cca/docker-compose.yml",
"echo '${data.template_file.cca-nginx-file.rendered}' > /cca/nginx.conf",
]
connection {
type = "ssh"
private_key = "${file(var.ssh_private_key)}"
user = "root"
timeout = "2m"
}
}
# copy coldbox application
provisioner "file" {
source = "app/"
destination = "/cca/app"
connection {
type = "ssh"
private_key = "${file(var.ssh_private_key)}"
user = "root"
timeout = "2m"
}
}
# start application
provisioner "remote-exec" {
inline = [
"cd /cca",
"docker-compose up -d > /dev/null 2>&1",
]
connection {
type = "ssh"
private_key = "${file(var.ssh_private_key)}"
user = "root"
timeout = "2m"
}
}
}
output "application_ip" {
value = "${digitalocean_droplet.application.ipv4_address}"
}