11
22//  coredns for service discovery
3- //  Docker Image: https://hub.docker.com/r /coredns/coredns/ 
3+ //  Docker Image: ghcr.io/mutablelogic /coredns-nomad 
44
55// /////////////////////////////////////////////////////////////////////////////
66//  VARIABLES
@@ -40,10 +40,10 @@ variable "service_dns" {
4040  default      =   []
4141}
4242
43- variable  "dns_servers "  {
44-   description  =  " Task DNS servers " 
45-   type         =  list ( string ) 
46-   default      =  [] 
43+ variable  "service_type "  {
44+   description  =  " Run as a service or system " 
45+   type         =  string 
46+   default      =  " service " 
4747}
4848
4949variable  "docker_image"  {
@@ -57,6 +57,8 @@ variable "docker_always_pull" {
5757  default      =  false 
5858}
5959
60+ // /////////////////////////////////////////////////////////////////////////////
61+ 
6062variable  "port"  {
6163  description  =  " Port for plaintext connections" 
6264  type         =  number 
@@ -102,7 +104,7 @@ locals {
102104//  JOB
103105
104106job  "coredns"  {
105-   type         =  " service " 
107+   type         =  var . service_type 
106108  datacenters  =   var. dc 
107109  namespace    =   var. namespace 
108110
@@ -115,7 +117,7 @@ job "coredns" {
115117  // ///////////////////////////////////////////////////////////////////////////////
116118
117119  group  "coredns"  {
118-     count  =  length (var. hosts ) ==  0  ?  1  :  length (var. hosts )
120+     count  =  ( length (var. hosts ) ==  0   ||  var . service_type   ==   " system " )  ?  1  :  length (var. hosts )
119121
120122    dynamic  "constraint"  {
121123      for_each  =  length (var. hosts ) ==  0  ?  [] :  [join (" ,"  , var. hosts )]
@@ -134,7 +136,7 @@ job "coredns" {
134136    }
135137
136138    service  {
137-       tags      =   [" dns"  ]
139+       tags      =   [" coredns " ,  " dns"  ]
138140      name      =   var. service_name 
139141      port      =  " dns" 
140142      provider  =   var. service_provider 
@@ -163,8 +165,8 @@ job "coredns" {
163165        image        =   var. docker_image 
164166        force_pull   =   var. docker_always_pull 
165167        ports        =   [" dns"  ]
166-         args         =   [" coredns"  , " -conf"  , local . core_file ]
167168        dns_servers  =   var. service_dns 
169+         args         =   [" coredns"  , " -conf"  , local . core_file ]
168170      }
169171
170172    } //  task "daemon"
0 commit comments