-
Notifications
You must be signed in to change notification settings - Fork 3
/
instances.tf
87 lines (76 loc) · 2.56 KB
/
instances.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
resource "digitalocean_droplet" "mypaas" {
image = "debian-9-x64"
count = "${var.instances}"
name = "${var.prefix}-${count.index+1}"
region = "${var.region}"
size = "${var.size}"
backups = "False"
ipv6 = "False"
private_networking = "False"
ssh_keys = ["${var.ssh_id}"]
# use this for remote connection
connection {
type = "ssh"
user = "root"
}
# Place your SSH public key on the
# remote machine to support the dokku setup
provisioner "file" {
source = "${var.ssh_prikey}.pub"
destination = "/root/.ssh/id_rsa.pub"
}
# Stick the bootstrap.sh onto the
# remote machine to do the dokku setup
provisioner "file" {
source = "./bootstrap.sh"
destination = "/root/bootstrap.sh"
}
# Update your remote VM and install dokku
provisioner "remote-exec" {
inline = [
"sh /root/bootstrap.sh ${var.prefix}.${var.domain}",
"dokku apps:create ${var.appname}",
"dokku config:set ${var.appname} CURL_CONNECT_TIMEOUT=30 CURL_TIMEOUT=300",
"dokku plugin:install https://github.com/dokku/dokku-postgres.git",
"dokku postgres:create rails-database",
"dokku postgres:link rails-database ${var.appname}",
"dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git",
]
}
}
# null resource used to reconnect to droplet
# after DNS record has been written
# (domain records should be available once
# app push is complete)
resource "null_resource" "letsencrypt" {
depends_on = [
"digitalocean_record.mypaas",
"digitalocean_record.wildcard",
]
triggers {
"mypaas" = "${digitalocean_droplet.mypaas.0.id}"
}
# use this for remote connection
connection {
host = "${digitalocean_droplet.mypaas.0.ipv4_address}"
type = "ssh"
user = "root"
}
# Push app to dokku server
provisioner "local-exec" {
command = "sh app_pusher.sh ${var.prefix}.${var.domain} ${var.appname} ${var.gitname}"
}
# Configure let's encrypt plugin and request ssl cert for app
provisioner "remote-exec" {
inline = [
"dokku config:set --no-restart ${var.appname} DOKKU_LETSENCRYPT_EMAIL=${var.email}",
"dokku letsencrypt ${var.appname}",
]
}
}
output "msg_hosts" {
value = "Your primary dokku host is: ${digitalocean_record.mypaas.fqdn} @ ${digitalocean_droplet.mypaas.0.ipv4_address}"
}
output "msg_apps" {
value = "Your first application is deployed at: https://${var.appname}.${digitalocean_record.mypaas.fqdn}"
}