ansble-terraform-jsonnet/lib/terraform.libsonnet

36 lines
1.2 KiB
Plaintext

local config = import "../config/config.libsonnet";
{
local terraform = self,
local rname (server, suffix) = "host_" + server.name + "_" + suffix,
HcloudInstance:: {
name: error "Instance must have field: name",
image: "debian-11",
server_type: error "Instance must have field: server_type",
location: "fsn1"
},
HcloudSSHKey:: {
name: error "Key must have field: name",
public_key: error "Key must have field: public_key",
labels: { source: "terraform" }
},
HdnsRecord:: {
zone_id: "${hetznerdns_zone.infra.id}",
name: error "Record must have field: name",
value: error "Record must have field: value",
type: error "Record must have field: type",
ttl: config.defaultTTL
},
serverDnsRecords: function (s) {
local attr (s, n) = "${hcloud_server." + s.name + "." + n + "}",
[rname(s, "A")]: terraform.HdnsRecord{ name: s.publicSubdomain, value: attr(s, "ipv4_address"), type: "A" },
[rname(s, "AAAA")]: terraform.HdnsRecord{ name: s.publicSubdomain, value: attr(s, "ipv6_address"), type: "AAAA" },
[rname(s, "VPN")]: terraform.HdnsRecord{ name: s.internalSubdomain, value: s.wireguardIp, type: "AAAA" },
}
}