hashicorp / hashicorp/consul-template
Variable is expanded at unpredictable way
- Dominant language
- Go
- Stars
- 4.8k
- Forks
- 801
- Avg merge
- 4h 5m
- Merged PRs (30d)
- 6
Description
### Consul Template version
consul-template v0.37.6 (358ff54)
### Configuration
```liquid
template {
destination = "local/script.sh"
data = <<-EOH
set -ex
cmd='bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup"'
nomad alloc exec -task postgres-task "${DB_ALLOC_ID}" ${cmd} || {
exit 1;
};
EOH
}
```
### Debug output
```
+ cmd='bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup"'
+ nomad alloc exec -task postgres-task a4ecf71b-3a7e-5a3b-cabd-2df187852011 bash -c '"source' '\${NOMAD_ALLOC_DIR}/creds.env;' 'backup"'
\${NOMAD_ALLOC_DIR}/creds.env;: -c: line 1: unexpected EOF while looking for matching `"'
```
### Expected behavior
The command should be:
```
"source" "\${NOMAD_ALLOC_DIR}/creds.env;" "backup"
```
### Actual behavior
```
"source' '\${NOMAD_ALLOC_DIR}/creds.env;' 'backup"
```
### Steps to reproduce
1. Nomad plan
2. Nomad run
3. "View logs" for the task.
### Thoughts
Also it could be
```
+ nomad alloc exec -task postgres-task a4ecf71b-xx bash -c 'source ${NOMAD_ALLOC_DIR}/creds.env; backup'
```
Notice, in the case above the string is `'source ${NOMAD_ALLOC_DIR}/creds.env; backup'`
For the template:
```
nomad alloc exec -task postgres-task "${db_alloc_id}" \
bash -c "source \${NOMAD_ALLOC_DIR}/creds.env; backup" || {
exit 1;
};
```
It should be the same for the case when I used $cmd.
Contributor guide
Assessment
This issue has not been assessed yet.