aboutsummaryrefslogtreecommitdiff
path: root/vps.tf
blob: e0c3262e69b2e880215760b5356fa70f6c6e01e6 (plain) (blame)
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
# Input variables

variable "vultr_api_key" {
  type        = string
  description = "Vultr API key."
}

variable "tld" {
  type        = string
  description = "Root Top-Level Domain. Subdomains will be derived from it."
}

variable "nextcloud_tld_prefix" {
  type        = string
  description = "DNS prefix used for the Nextcloud installation. Does not contain a dot at the end."
}

variable "hostname" {
  type        = string
  description = "Human name of the host. This is a pet name, not cattle name :)"
}

variable "storage_name" {
  type        = string
  description = "Name of the block storage volume, which will also be the name of it's mount point."
}


# Vultr

provider "vultr" {
  api_key = var.vultr_api_key
  version = "~> 1.3"
}


# Instance

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"
}

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"
}


# DNS and IP configuration

output "public_ip" {
  value = vultr_server.vps_server.main_ip
}

resource "vultr_dns_domain" "vps_tld" {
  domain    = var.tld
  server_ip = vultr_server.vps_server.main_ip
}

resource "vultr_dns_record" "at_sign" {
  domain = var.tld
  type   = "A"
  name   = "@"
  data   = vultr_server.vps_server.main_ip
}

resource "vultr_dns_record" "nextcloud" {
  domain = var.tld
  type   = "CNAME"
  name   = var.nextcloud_tld_prefix
  data   = vultr_server.vps_server.main_ip
}