This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
79 lines (68 loc) · 2.63 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
# terraform-digitalocean-cjdns-node
# ============================================================================
# Copyright (c) 2018 Verb Networks Pty Ltd <contact [at] verbnetworks.com>
# - All rights reserved.
#
# Apache License v2.0
# - http://www.apache.org/licenses/LICENSE-2.0
# user_data
# ============================================================================
data "template_file" "cloud-config" {
template = "${file("${path.module}/etc/cloud-config.yaml")}"
vars {
user = "${var.user}"
user_sshkey = "${var.user_sshkey}"
}
}
data "template_file" "cloud-config-bootstrap-sh" {
template = "${file("${path.module}/etc/cloud-config-bootstrap.sh")}"
vars {
cjdns_commit = "${var.cjdns_commit}"
ipfs_version = "${var.ipfs_version}"
hostname = "${var.hostname}"
}
}
data "template_cloudinit_config" "node-userdata" {
gzip = false # cloud-init bug seems to prevent this from being enabled as at 2017-12
base64_encode = false #
part {
content_type = "text/cloud-config"
content = "${data.template_file.cloud-config.rendered}"
}
part {
content_type = "text/x-shellscript"
content = "${data.template_file.cloud-config-bootstrap-sh.rendered}"
filename = "cloud-config-bootstrap.sh"
}
}
# digitalocean_droplet
# ============================================================================
resource "digitalocean_droplet" "droplet_node" {
image = "${var.image}"
name = "${var.hostname}"
region = "${var.region}"
size = "${var.size}"
backups = "${var.backups}"
monitoring = "${var.monitoring}"
ipv6 = "${var.ipv6}"
private_networking = "${var.private_networking}"
//ssh_keys = [ "0" ]
user_data = "${data.template_cloudinit_config.node-userdata.rendered}"
}
# NB: there is a very strong temptation to use floating_ip addresses here, as at
# writing (2017-12-30) the Terraform exposed Digital Ocean interface does not
# provide the right functionality to correctly implement static IPv4
# addresses without clobbering (hence loosing) them. If you require static
# IPv4 addresses you'll need to use the Digital Ocean webui manually.
# push-cjdns-config
# ============================================================================
resource "null_resource" "push-cjdns-config-sh" {
triggers {
droplet_node_id = "${digitalocean_droplet.droplet_node.id}"
cjdroute_config_sha1= "${sha1(file(var.cjdroute_config))}"
}
provisioner "local-exec" {
command = "${path.module}/etc/push-cjdns-config.sh ${var.cjdroute_config} ${digitalocean_droplet.droplet_node.ipv4_address}"
}
depends_on = [ "digitalocean_droplet.droplet_node" ]
}