diff --git a/command/agent/agent.go b/command/agent/agent.go index cd8cd9085..c9be8c052 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -577,7 +577,7 @@ func (a *Agent) setupServer() error { httpServ := &structs.Service{ Name: a.config.Consul.ServerServiceName, PortLabel: a.config.AdvertiseAddrs.HTTP, - Tags: []string{consul.ServiceTagHTTP}, + Tags: append([]string{consul.ServiceTagHTTP}, a.config.Consul.Tags...), } const isServer = true if check := a.agentHTTPCheck(isServer); check != nil { @@ -586,7 +586,7 @@ func (a *Agent) setupServer() error { rpcServ := &structs.Service{ Name: a.config.Consul.ServerServiceName, PortLabel: a.config.AdvertiseAddrs.RPC, - Tags: []string{consul.ServiceTagRPC}, + Tags: append([]string{consul.ServiceTagRPC}, a.config.Consul.Tags...), Checks: []*structs.ServiceCheck{ { Name: a.config.Consul.ServerRPCCheckName, @@ -600,7 +600,7 @@ func (a *Agent) setupServer() error { serfServ := &structs.Service{ Name: a.config.Consul.ServerServiceName, PortLabel: a.config.AdvertiseAddrs.Serf, - Tags: []string{consul.ServiceTagSerf}, + Tags: append([]string{consul.ServiceTagSerf}, a.config.Consul.Tags...), Checks: []*structs.ServiceCheck{ { Name: a.config.Consul.ServerSerfCheckName, @@ -742,7 +742,7 @@ func (a *Agent) setupClient() error { httpServ := &structs.Service{ Name: a.config.Consul.ClientServiceName, PortLabel: a.config.AdvertiseAddrs.HTTP, - Tags: []string{consul.ServiceTagHTTP}, + Tags: append([]string{consul.ServiceTagHTTP}, a.config.Consul.Tags...), } const isServer = false if check := a.agentHTTPCheck(isServer); check != nil { diff --git a/nomad/structs/config/consul.go b/nomad/structs/config/consul.go index 750d1b916..3660a94e8 100644 --- a/nomad/structs/config/consul.go +++ b/nomad/structs/config/consul.go @@ -43,6 +43,10 @@ type ConsulConfig struct { // to register the client HTTP health check with Consul ClientHTTPCheckName string `hcl:"client_http_check_name"` + // Tags are optional service tags that get registered with the service + // in Consul + Tags []string `hcl:"tags"` + // AutoAdvertise determines if this Nomad Agent will advertise its // services via Consul. When true, Nomad Agent will register // services with Consul. @@ -136,6 +140,7 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig { if b.ClientHTTPCheckName != "" { result.ClientHTTPCheckName = b.ClientHTTPCheckName } + result.Tags = append(result.Tags, b.Tags...) if b.AutoAdvertise != nil { result.AutoAdvertise = helper.BoolToPtr(*b.AutoAdvertise) } @@ -233,7 +238,6 @@ func (c *ConsulConfig) ApiConfig() (*consul.Config, error) { } config.Transport.TLSClientConfig = tlsConfig } - return config, nil } diff --git a/website/source/docs/configuration/consul.html.md b/website/source/docs/configuration/consul.html.md index 2f183652e..274c55e70 100644 --- a/website/source/docs/configuration/consul.html.md +++ b/website/source/docs/configuration/consul.html.md @@ -108,6 +108,9 @@ configuring Nomad to talk to Consul via DNS such as consul.service.consul - `ssl` `(bool: false)` - Specifies if the transport scheme should use HTTPS to communicate with the Consul agent. +- `tags` `(array: [])` - Specifies optional Consul tags to be + registered with the Nomad server and agent services. + - `token` `(string: "")` - Specifies the token used to provide a per-request ACL token. This option overrides the Consul Agent's default token. If the token is not set here or on the Consul agent, it will default to Consul's anonymous policy,