aboutsummaryrefslogtreecommitdiff
path: root/vps.tf
diff options
context:
space:
mode:
Diffstat (limited to 'vps.tf')
-rw-r--r--vps.tf108
1 files changed, 39 insertions, 69 deletions
diff --git a/vps.tf b/vps.tf
index 8579e76..e0c3262 100644
--- a/vps.tf
+++ b/vps.tf
@@ -1,8 +1,8 @@
# Input variables
-variable "do_token" {
+variable "vultr_api_key" {
type = string
- description = "DigitalOcean API token."
+ description = "Vultr API key."
}
variable "tld" {
@@ -20,95 +20,65 @@ variable "hostname" {
description = "Human name of the host. This is a pet name, not cattle name :)"
}
-variable "volume_name" {
+variable "storage_name" {
type = string
- description = "Name of the volume, which will also be the name of it's mount point."
+ description = "Name of the block storage volume, which will also be the name of it's mount point."
}
-# DigitalOcean
-provider "digitalocean" {
- token = var.do_token
- version = "~> 1.1"
-}
+# Vultr
-resource "digitalocean_ssh_key" "client" {
- name = "terraform-vps-client"
- public_key = file("${path.module}/secrets/ssh/vps-box-client.pub")
+provider "vultr" {
+ api_key = var.vultr_api_key
+ version = "~> 1.3"
}
-## Droplet and volume
-
-resource "digitalocean_droplet" "vps" {
- image = "ubuntu-18-04-x64"
- name = var.hostname
- region = "nyc3"
- size = "s-1vcpu-1gb"
- backups = true
- ipv6 = true
- monitoring = true
-
- user_data = file("${path.module}/generated/user-data.sh")
-
- ssh_keys = [
- "${digitalocean_ssh_key.client.fingerprint}",
- ]
-
- connection {
- user = "root"
- type = "ssh"
- private_key = file("${path.module}/secrets/ssh/vps-box-client")
- timeout = "2m"
- host = digitalocean_droplet.vps.ipv6_address
- }
-
- provisioner "remote-exec" {
- inline = ["echo 'SSH is up! Noop remote-exec is done.'"]
- }
-}
-resource "digitalocean_volume" "vps_persistent_volume" {
- region = "nyc3"
- name = var.volume_name
- size = 10
- initial_filesystem_type = "ext4"
- description = "Persistent disk to store docker volumes contents across droplets being created and destroyed"
-}
+# Instance
-resource "digitalocean_volume_attachment" "foobar" {
- volume_id = digitalocean_volume.vps_persistent_volume.id
- droplet_id = digitalocean_droplet.vps.id
+resource "vultr_server" "vps_server" {
+ enable_ipv6 = true
+ notify_activate = true
+ hostname = var.hostname
+ label = var.hostname
+ # $ curl https://api.vultr.com/v1/regions/list | jq '.["9"]'
+ region_id = 9
+ # $ curl https://api.vultr.com/v1/plans/list?type=vc2 | jq '.["201"]'
+ plan_id = 201
+ # $ curl -H "API-Key: $TF_VAR_vultr_api_key" https://api.vultr.com/v1/snapshot/list | jq
+ snapshot_id = "7245f30a2f3b3"
}
-## DNS and IP configuration
-
-resource "digitalocean_floating_ip" "vps_public_ip" {
- region = digitalocean_droplet.vps.region
+resource "vultr_block_storage" "vps_storage" {
+ size_gb = 10
+ region_id = 9
+ attached_id = vultr_server.vps_server.id
+ label = var.storage_name
+ live = "yes"
}
-resource "digitalocean_floating_ip_assignment" "vps_public_ip_assignment" {
- ip_address = digitalocean_floating_ip.vps_public_ip.id
- droplet_id = digitalocean_droplet.vps.id
-}
-output "public_floating_ip" {
- value = digitalocean_floating_ip.vps_public_ip.ip_address
+# DNS and IP configuration
+
+output "public_ip" {
+ value = vultr_server.vps_server.main_ip
}
-resource "digitalocean_domain" "vps_tld" {
- name = var.tld
+resource "vultr_dns_domain" "vps_tld" {
+ domain = var.tld
+ server_ip = vultr_server.vps_server.main_ip
}
-resource "digitalocean_record" "at_sign" {
- domain = digitalocean_domain.vps_tld.name
+resource "vultr_dns_record" "at_sign" {
+ domain = var.tld
type = "A"
name = "@"
- value = digitalocean_floating_ip.vps_public_ip.ip_address
+ data = vultr_server.vps_server.main_ip
}
-resource "digitalocean_record" "nextcloud" {
- domain = digitalocean_domain.vps_tld.name
+resource "vultr_dns_record" "nextcloud" {
+ domain = var.tld
type = "CNAME"
name = var.nextcloud_tld_prefix
- value = "${digitalocean_domain.vps_tld.name}."
+ data = vultr_server.vps_server.main_ip
}