Skip to content

Commit 319900f

Browse files
committed
Use node attribute to determine IP
${attr.unique.network.ip-address} has the host's IP. Use that for `-retry-join` instead of assuming the user mode networking IP (10.0.2.15).
1 parent 5e57d74 commit 319900f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mkosi.images/terraform/share/terraform/consul.nomad

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ job "consul" {
3434
template {
3535
data = <<-EOF
3636
encrypt = "{{ with secret "secrets/mangos/consul/gossip" }}{{ .Data.encryption_key | trimSpace }}{{ end }}"
37-
node_name = "consul-api-{{ env "NOMAD_SHORT_ALLOC_ID" }}"
3837
addresses {
3938
dns = "0.0.0.0"
4039
}
40+
node_name = "consul-api-{{ env "NOMAD_SHORT_ALLOC_ID" }}"
4141
acl {
4242
enabled = true
4343
tokens {
@@ -52,11 +52,17 @@ job "consul" {
5252
destination = "${NOMAD_SECRETS_DIR}/consul.hcl"
5353
change_mode = "restart"
5454
}
55+
5556
driver = "docker"
57+
58+
env {
59+
HOST_IP = "${attr.unique.network.ip-address}"
60+
}
61+
5662
config {
5763
image = "hashicorp/consul"
5864
args = ["agent",
59-
"-retry-join", "10.0.2.15",
65+
"-retry-join", "${HOST_IP}",
6066
"-datacenter", "${NOMAD_REGION}-${NOMAD_DC}",
6167
"-config-file", "${NOMAD_SECRETS_DIR}/consul.hcl"]
6268
}

0 commit comments

Comments
 (0)