-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.tf
106 lines (93 loc) · 1.95 KB
/
root.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
terraform {
required_providers {
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.48.0"
}
hetznerdns = {
source = "timohirt/hetznerdns"
version = "~> 2.2.0"
}
}
}
variable "hcloud_token" {
sensitive = true
}
variable "hdns_token" {
sensitive = true
}
variable "hdns_domain" {
sensitive = false
}
provider "hcloud" {
token = var.hcloud_token
}
provider "hetznerdns" {
apitoken = var.hdns_token
}
resource "hcloud_ssh_key" "mckey" {
name = "minecraft_key"
public_key = file("mckey.pub")
}
resource "hcloud_volume" "mcworld" {
name = "MC-world"
size = 10
delete_protection = true
automount = true
format = "ext4"
labels = {
minecraft = 1
}
lifecycle {
prevent_destroy = true
}
}
resource "hetznerdns_zone" "zone1" {
name = var.hdns_domain
ttl = 300
}
data "template_file" "cloudinit" {
template = file("cloud-init.yml")
vars = {
docker-compose = base64gzip(file("docker-compose.yml"))
volume_path = "/dev/sdb"
}
}
data "cloudinit_config" "foobar" {
gzip = false
base64_encode = false
part {
filename = "cloud-config.yaml"
content_type = "text/cloud-config"
content = file("cloud-init.yml")
}
}
resource "hcloud_volume_attachment" "mcvolattach" {
volume_id = hcloud_volume.mcworld.id
server_id = hcloud_server.minecraft.id
automount = true
}
resource "hcloud_server" "minecraft" {
name = "Minecraft"
server_type = "cx32"
image = "docker-ce"
labels = {
minecraft = 1
}
location = "nbg1"
public_net {
ipv4_enabled = true
ipv6_enabled = true
}
ssh_keys = [
hcloud_ssh_key.mckey.name,
]
user_data = data.template_file.cloudinit.rendered
}
resource "hetznerdns_record" "minecraft" {
zone_id = hetznerdns_zone.zone1.id
name = "minecraft"
value = hcloud_server.minecraft.ipv4_address
type = "A"
ttl = 60
}