2021-12-09 01:12:59 +07:00
|
|
|
provider "cloudflare" {
|
|
|
|
# Environment variables
|
|
|
|
# CLOUDFLARE_API_KEY
|
2021-12-08 09:24:09 +07:00
|
|
|
}
|
|
|
|
|
2021-12-09 01:12:59 +07:00
|
|
|
data "cloudflare_zone" "khuedoan_com" {
|
|
|
|
name = "khuedoan.com"
|
2021-12-08 09:24:09 +07:00
|
|
|
}
|
|
|
|
|
2021-12-09 01:12:59 +07:00
|
|
|
resource "random_password" "tunnel_secret" {
|
2021-12-08 09:24:09 +07:00
|
|
|
length = 64
|
|
|
|
special = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "cloudflare_argo_tunnel" "homelab" {
|
|
|
|
# TODO (optimize) Use variable for account_id
|
|
|
|
account_id = "xxx"
|
|
|
|
name = "homelab"
|
2021-12-09 01:12:59 +07:00
|
|
|
secret = base64encode(random_password.tunnel_secret.result)
|
2021-12-08 09:24:09 +07:00
|
|
|
}
|
|
|
|
|
2021-12-09 01:12:59 +07:00
|
|
|
resource "cloudflare_record" "tunnels" {
|
|
|
|
for_each = toset([
|
|
|
|
"git"
|
|
|
|
])
|
|
|
|
|
|
|
|
zone_id = data.cloudflare_zone.khuedoan_com.id
|
2021-12-08 09:24:09 +07:00
|
|
|
type = "CNAME"
|
2021-12-09 01:12:59 +07:00
|
|
|
name = each.key
|
2021-12-08 09:24:09 +07:00
|
|
|
value = "${cloudflare_argo_tunnel.homelab.id}.cfargotunnel.com"
|
|
|
|
proxied = true
|
|
|
|
ttl = 1 # Auto
|
|
|
|
}
|
2021-12-09 01:12:59 +07:00
|
|
|
|
|
|
|
# TODO
|
|
|
|
# api token
|
|
|
|
# add it to certmanager, external-dns, cloudflaredknamespace
|