aboutsummaryrefslogtreecommitdiff
path: root/vps.tf
blob: 3fa9e129b2dd10d25df94568e0413b538fc06477 (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
# 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 "hostname" {
  type        = string
  description = "Human name of the host. This is a pet name, not cattle name :)"
}


# 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 = "c565f318e4aea"
}

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


# DNS and IP configuration

resource "vultr_dns_domain" "vps_tld" {
  # The CNAME record is already generated by Vultr
  domain    = var.tld
  server_ip = vultr_server.vps_server.main_ip
}