diff options
author | EuAndreh <eu@euandre.org> | 2019-06-10 09:03:58 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2019-06-10 09:11:27 -0300 |
commit | 95fb2c190a2143ab84be1b18fdd2ec587e54d05e (patch) | |
tree | 52737ee757a87edc88227c3da8c378e134183689 /vps.tf | |
parent | Change $TLD (diff) | |
download | server-95fb2c190a2143ab84be1b18fdd2ec587e54d05e.tar.gz server-95fb2c190a2143ab84be1b18fdd2ec587e54d05e.tar.xz |
Provision DNS entries using DigitalOcean instead of DNS registrar
This way we can implement dynamic (provision-time) Floating IP, instead of a
hardcoded pre-created Floating IP address.
Related changes:
- remove =terraform-godaddy= provider, use =digitalocean_record= instead;
- create =generated-known-hosts= after provisioning instead of during
=setup.sh=: use the =$(terraform output public_floating_ip)= value to make this
file dynamic;
- remote the =$PINNED_IP= and =$TF_VAR_floating_ip= variables;
- add type and descriptions to variable declarations in Terraform recipe.
Diffstat (limited to 'vps.tf')
-rw-r--r-- | vps.tf | 78 |
1 files changed, 50 insertions, 28 deletions
@@ -1,9 +1,22 @@ -variable "floating_ip" {} +variable "do_token" { + type = "string" + description = "DigitalOcean API token." +} + +variable "tld" { + type = "string" + description = "Root Top-Level Domain. Subdomains will be derived from it." +} -variable "do_token" {} -variable "tld" {} -variable "wallabag_tld" {} -variable "nextcloud_tld" {} +variable "wallabag_tld_prefix" { + type = "string" + description = "DNS prefix used for the Wallabag installation. Does not contain a dot at the end." +} + +variable "nextcloud_tld_prefix" { + type = "string" + description = "DNS prefix used for the Nextcloud installation. Does not contain a dot at the end." +} provider "digitalocean" { token = "${var.do_token}" @@ -42,11 +55,6 @@ resource "digitalocean_droplet" "vps" { } } -resource "digitalocean_floating_ip_assignment" "vps" { - ip_address = "${var.floating_ip}" - droplet_id = "${digitalocean_droplet.vps.id}" -} - resource "digitalocean_volume" "vps_persistent_volume" { region = "nyc3" name = "vps-persistent-volume" @@ -60,26 +68,40 @@ resource "digitalocean_volume_attachment" "foobar" { droplet_id = "${digitalocean_droplet.vps.id}" } -locals { - cname_subdomains = [ - "${var.wallabag_tld}", - "${var.nextcloud_tld}", - ] +resource "digitalocean_floating_ip" "vps_public_ip" { + region = "${digitalocean_droplet.vps.region}" } -resource "godaddy_domain_record" "vps_tld" { - domain = "${var.tld}" - addresses = ["${var.floating_ip}"] +resource "digitalocean_floating_ip_assignment" "vps_public_ip_assignment" { + ip_address = "${digitalocean_floating_ip.vps_public_ip.id}" + droplet_id = "${digitalocean_droplet.vps.id}" +} - record { - type = "CNAME" - name = "${var.tld}" - data = "${var.wallabag_tld}" - } +output "public_floating_ip" { + value = "${digitalocean_floating_ip.vps_public_ip.ip_address}" +} - record { - type = "CNAME" - name = "${var.tld}" - data = "${var.nextcloud_tld}" - } +resource "digitalocean_domain" "vps_tld" { + name = "${var.tld}" +} + +resource "digitalocean_record" "at_sign" { + domain = "${digitalocean_domain.vps_tld.name}" + type = "A" + name = "@" + value = "${digitalocean_floating_ip.vps_public_ip.ip_address}" +} + +resource "digitalocean_record" "wallabag" { + domain = "${digitalocean_domain.vps_tld.name}" + type = "CNAME" + name = "${var.wallabag_tld_prefix}" + value = "${digitalocean_domain.vps_tld.name}." +} + +resource "digitalocean_record" "nextcloud" { + domain = "${digitalocean_domain.vps_tld.name}" + type = "CNAME" + name = "${var.nextcloud_tld_prefix}" + value = "${digitalocean_domain.vps_tld.name}." } |