terraform-provider-template
terraform-provider-template copied to clipboard
Unsupported functions in template file
Hello!
Looks like there are unsupported functions in template file.
Documentation says "The template may also use any other function available in the Terraform language, except that recursive calls to templatefile are not permitted" but i found out that neither 'regex' nor 'regexall' are in fact supported:
Terraform Version
me@my-mac ~/Code/consul-vault/app/staging $ terraform -v Terraform v0.12.24
- provider.null v2.1.2
- provider.template v2.1.2
- provider.vsphere v1.17.2
Affected Resource(s)
- data.template_file
Terraform Configuration Files
data "template_file" "consul_config" {
template = file("${path.module}/consul_config.json.tmpl")
count = length(var.ipv4_addresses)
vars = {
node_name = format("${var.vm_prefix}-%02d", count.index +1)
datacenter = "dc"
svc_domain = "service.local"
bind_addr = var.ipv4_addresses[count.index]
advertise_addr = var.ipv4_addresses[count.index]
client_addr = "0.0.0.0"
bootstrap_expect = length(var.ipv4_addresses)
retry_join = jsonencode(var.ipv4_addresses)
}
}
Template file
{
%{ if regex(".+consul.+", node_name) }
"server": true,
"domain": "${svc_domain}",
"bootstrap_expect": ${bootstrap_expect},
"ui": true,
%{ endif ~}
"node_name": "${node_name}",
"datacenter": "${datacenter}",
"data_dir": "/consul/data",
"bind_addr": "${bind_addr}",
"advertise_addr": "${advertise_addr}",
"client_addr": "${client_addr}",
"retry_join": ${retry_join},
"log_level": "INFO",
"acl_enforce_version_8": false
}
Panic Output
Error: failed to render : <template_file>:2,7-12: Call to unknown function; There is no function named "regex".
on ../../modules/provision.tf line 1, in data "template_file" "consul_config": 1: data "template_file" "consul_config" {
Similar error is produced if i try to use %{ if length(regexall(".+consul.+", node_name)) > 0 } in template:
Error: failed to render : <template_file>:2,14-22: Call to unknown function; There is no function named "regexall".
on ../../modules/provision.tf line 1, in data "template_file" "consul_config": 1: data "template_file" "consul_config" {
Expected Behavior
As documentation implies all terraform functions should be supported in template file except recursive calls to templatefile
Actual Behavior
Template fails to render
Steps to Reproduce
- Create a template using regex or regexall function in it
- run
terraform apply
https://github.com/hashicorp/terraform-provider-template/blob/master/template/datasource_template_file.go#L125