Skip to content

Commit bb7c67c

Browse files
committed
Adjust Consul networking
Changing "static" to "to" for the http port means a dynamic port is assigned and it's no longer exposed on port 8500 of the host. Add a separate service for DNS that resolves to the host's IP.
1 parent 319900f commit bb7c67c

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

mkosi.images/terraform/share/terraform/consul-service.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ resource "consul_config_entry_service_intentions" "consul" {
6464

6565
resource "nomad_job" "consul" {
6666
jobspec = file("${path.module}/consul.nomad")
67+
hcl2 {
68+
vars = {
69+
namespace = nomad_namespace.admin.name
70+
}
71+
}
6772
depends_on = [
68-
nomad_namespace.admin,
6973
vault_consul_secret_backend_role.consul-api,
7074
vault_jwt_auth_backend_role.consul,
7175
consul_acl_binding_rule.consul-service,

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

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
1+
variable "namespace" {
2+
type = string
3+
}
4+
15
job "consul" {
2-
namespace = "admin"
6+
namespace = var.namespace
37

48
group "client" {
59
service {
6-
tags = ["api"]
7-
name = "consul"
8-
port = "http"
10+
tags = ["api"]
11+
name = "consul"
12+
port = "http"
13+
address_mode = "alloc"
914
connect {
1015
sidecar_service {}
1116
}
1217
}
1318

19+
service {
20+
tags = ["dns"]
21+
name = "consul"
22+
port = "dns"
23+
address_mode = "host"
24+
}
25+
1426
network {
1527
mode = "bridge"
1628
port "http" {
17-
static = 8500
29+
to = 8500
1830
}
1931
port "dns" {
2032
static = 8600
@@ -32,7 +44,7 @@ job "consul" {
3244
consul {}
3345

3446
template {
35-
data = <<-EOF
47+
data = <<-EOF
3648
encrypt = "{{ with secret "secrets/mangos/consul/gossip" }}{{ .Data.encryption_key | trimSpace }}{{ end }}"
3749
addresses {
3850
dns = "0.0.0.0"
@@ -61,10 +73,12 @@ job "consul" {
6173

6274
config {
6375
image = "hashicorp/consul"
64-
args = ["agent",
65-
"-retry-join", "${HOST_IP}",
66-
"-datacenter", "${NOMAD_REGION}-${NOMAD_DC}",
67-
"-config-file", "${NOMAD_SECRETS_DIR}/consul.hcl"]
76+
args = [
77+
"agent",
78+
"-retry-join", "${HOST_IP}",
79+
"-datacenter", "${NOMAD_REGION}-${NOMAD_DC}",
80+
"-config-file", "${NOMAD_SECRETS_DIR}/consul.hcl"
81+
]
6882
}
6983
}
7084
}

0 commit comments

Comments
 (0)