-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
56 lines (50 loc) · 1.29 KB
/
main.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
resource "hcloud_server" "node1" {
name = "node1"
image = "ubuntu-20.04"
server_type = "cx11"
location = "hel1" # helsinki
ssh_keys = [
hcloud_ssh_key.local_ssh_key.id,
]
labels = {
"domain" = var.site_domain
}
user_data = templatefile("user_data.tftpl", { "pubkey" = file("~/.ssh/id_ed25519.pub") })
}
resource "hcloud_ssh_key" "local_ssh_key" {
name = "Terraform local machine SSH key"
public_key = file("~/.ssh/id_ed25519.pub")
labels = {}
}
data "cloudflare_zones" "domain" {
filter {
name = var.site_domain
}
}
resource "cloudflare_record" "site_cname" {
zone_id = data.cloudflare_zones.domain.zones[0].id
name = var.site_domain
value = hcloud_server.node1.ipv4_address
type = "A"
ttl = 1
proxied = true
}
resource "cloudflare_record" "site_www" {
zone_id = data.cloudflare_zones.domain.zones[0].id
name = "www"
value = var.site_domain
type = "CNAME"
ttl = 1
proxied = true # Proxy for web traffic
}
resource "cloudflare_record" "site_ssh" {
zone_id = data.cloudflare_zones.domain.zones[0].id
name = "ssh"
value = var.site_domain
type = "CNAME"
ttl = 1
proxied = false # Don't proxy so we can ssh in
}
output "instance_ip_addr" {
value = hcloud_server.node1.ipv4_address
}