From 2f03b5c8b55a9c338171dbf86540d6fc127cd773 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sat, 6 Apr 2024 00:36:43 +0200 Subject: [PATCH] Allow getting service config from a common place connect_services --- templates/connect | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/templates/connect b/templates/connect index 92d9920..33edb69 100644 --- a/templates/connect +++ b/templates/connect @@ -13,13 +13,23 @@ [[- range $idx, $upstream := .consul.connect.upstreams ]] [[- $connect_services = append $upstream.destination_name $connect_services ]] upstreams { - destination_name = [[ $upstream.destination_name | toJSON ]] + destination_name = "[[ $upstream.destination_name ]]" + [[- if has $upstream "local_bind_port" ]] local_bind_port = [[ $upstream.local_bind_port ]] + [[- else if and (has $ "connect_services") (has $.connect_services $upstream.destination_name) (has (index $.connect_services $upstream.destination_name) "port") ]] + local_bind_port = [[ (index $.connect_services $upstream.destination_name).port ]] + [[- end ]] # Work arround, see https://github.com/hashicorp/nomad/issues/18538 destination_type = "service" + [[- $config := dict ]] [[- if has $upstream "config" ]] + [[- $config = $upstream.config ]] + [[- else if and (has $ "connect_services") (has $.connect_services $upstream.destination_name) (has (index $.connect_services $upstream.destination_name) "config") ]] + [[- $config = (index $.connect_services $upstream.destination_name).config ]] + [[- end ]] + [[- if gt (len $config) 0 ]] config { - [[- range $k, $v := $upstream.config ]] + [[- range $k, $v := $config ]] [[- if or (isKind "number" $v) (isKind "bool" $v) ]] [[ $k ]] = [[ $v ]] [[- else if isKind "string" $v ]]