1

I'm trying to use terraform to set up consul servers on Hetzner Cloud with private network.

Since Hetzner doesn't support auto-join yet, is it possible to use go-sockaddr's GetPrivateIPs to get all private IPs available for retry_join in the config file? The go-sockaddr document says GetPrivateIPs will return a space-separated string with all IPs. How can I make use of this function for the config?

From what I've read, the retry_join requires a literal array like this: ["10.0.0.6", "10.0.0.7"]

Here is the setting in etc/consul.d/server.hcl:

  server = true
  bootstrap_expect = ${consul_instances}
  client_addr = "127.0.0.1"
  data_dir = "/opt/consul"
  bind_addr = "{{GetPrivateInterfaces | include \"network\" \"${ip_range}\" | attr \"address\"}}"
  retry_join = "{{GetPrivateIPs}}" // Is there a way to turn it into ["10.0.0.6", "10.0.0.7"]?

Here's the terraform data block that renders the server.hcl with variables:

data template_file "server_config" {
  template = file("${path.module}/server.hcl")
  vars = {
    consul_instances = 3
    ip_range = "10.0.0.0/8"
  }
}
RedGiant
  • 4,444
  • 11
  • 59
  • 146

0 Answers0