Encode symfony database url within nomad template with go
Aug 3, 2022
When you password contains % or other special chars in the doctrine DSN, then you need to escape them by doubling them:
{{ .Data.data.password | urlquery | replaceAll "%" "%%" }}
Full snippet to create the DSN for doctrine from several parts:
{{ with secret "secret/data/web/database" }}
DATABASE_URL="mysql://{{ .Data.data.user }}:{{ .Data.data.password | urlquery | replaceAll "%" "%%" }}@{{ .Data.data.vlanIp }}:{{ .Data.data.vlanPort }}/${var.database_name}?serverVersion=5.7"
{{ end }}
reference wich advanced filters and methods you can use in hcl2 is in the consul template docs:
https://github.com/hashicorp/consul-template/blob/main/docs/templating-language.md