hashicorp / hashicorp/consul-template
Ability to Use Prepared Query in Place of Service
- Dominant language
- Go
- Stars
- 4.8k
- Forks
- 801
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 6
Description
Please note that the Consul Template issue tracker is reserved
for bug reports and enhancements. For general usage questions,
please use the Consul mailing list:
https://groups.google.com/forum/#!forum/consul-tool
### Consul Template version
```
consul-template v0.18.5 (9902dd5)
```
### Configuration
```hcl
N/A
```
```liquid
upstream exampleservice {
least_conn;
keepalive 16;
#Attempt to fetch the exampleservice servers
{{if service "exampleservice"}}
{{range service "exampleservice"}}server {{.Address}}:8443;
{{end}}
{{else}} # upstream stanza must have a server directive
server 127.0.0.1 down;
{{end}}
}
```
### Command
```shell
consul-template --template=/etc/templates/etc/nginx/virtual-servers/pws.conf:/etc/nginx/virtual-servers/pws.conf:systemctl reload nginx --template=/etc/templates/etc/nginx/locations/pws.conf:/etc/nginx/locations/pws.conf:systemctl reload nginx --template=/etc/templates/etc/nginx/upstreams/pws.conf:/etc/nginx/upstreams/pws.conf:systemctl reload nginx --wait=5s:10s
```
### Debug output
N/A
### Expected behavior
This is a feature request, so what I'd like to be able to do is something like this:
```liquid
upstream exampleservice {
least_conn;
keepalive 16;
#Attempt to fetch the exampleservice servers
{{if query "exampleservice"}}
{{range query "exampleservice"}}server {{.Address}}:8443;
{{end}}
{{else}} # upstream stanza must have a server directive
server 127.0.0.1 down;
{{end}}
}
```
### Actual behavior
In the absence of using prepared queries, we are constrained to only having services within a given datacenter with the configuration as it exists. We could define a second section, with a hard coded backup:
```liquid
upstream exampleservice {
least_conn;
keepalive 16;
#Attempt to fetch the exampleservice servers
{{if service "exampleservice"}}
{{range service "exampleservice"}}server {{.Address}}:8443;
{{end}}
{{else}} # upstream stanza must have a server directive
server 127.0.0.1 down;
{{end}}
#Attempt to fetch the backup exampleservice servers
{{if service "exampleservice@guse4-poc"}}
{{range service "exampleservice@guse4-poc"}}server {{.Address}}:8443 backup;
{{end}}
{{else}} # upstream stanza must have a server directive
server 127.0.0.1 down;
{{end}}
}
```
But that gets tricky to maintain, and query seems like the perfect solution for this, if it were an option to iterate over, as service is.
### Steps to reproduce
N/A
### References
Are there any other GitHub issues (open or closed) that should
be linked here? For example:
N/A
Contributor guide
Research direction
No files, tests, or entry points are named. Start by examining the existing `service` template behavior and the requested Consul prepared-query behavior; done means templates can conditionally iterate over query results as shown, while preserving the fallback configuration pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devops
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100