hashicorp / hashicorp/consul-template

Defining consul-template based on hostname environment variable

Open
#1,371 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
4.8k
Forks
801
Avg merge
4h 5m
Merged PRs (30d)
6

Description

### Consul Template version

consul-template v0.16.0

### Configuration

```hcl
{{ $host := env "HOSTNAME" }}
{{ $regex := "^b" }}
{{ if $host | regexMatch "^a" }}{{ $regex := "^a" }}{{ end }}
{{ range service "service-name" }}
{{- if .Node | regexMatch $regex -}}server {{.Node}} {{.Address}}:{{.Port}}
{{ end }}{{ end }}
```

### Expected behavior
Since hostname starts with "a" - I expect to get nodes which match regex "^a".

### Actual behavior
Consul-template renders nodes which match regex "^b".

### Steps to reproduce

1. Write block with the template lines above in consul template file.
2. Run consul-template.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided template configuration with consul-template v0.16.0 and inspect how variables assigned inside the if block are scoped. Add a regression test for the HOSTNAME values beginning with "a" and "b"; done means the rendered service nodes use the corresponding regex in each case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.