I have been using the templatefile function to pass variables to a config template, then echo the content into a file, but I just ran into a problem with Consul config files. I can’t find a way to get Packer to ignore the GetPrivateInterfaces function for bind_addr unless the double curly braces are escaped, but by doing that Consul would fail to parse the config. Is there any solution?
consul-config.tpl:
datacenter = \"${datacenter}\"
ca_file = \"/etc/consul.d/consul-agent-ca.pem\"
data_dir = \"/opt/consul\"
client_addr = \"127.0.0.1\"
verify_incoming = ${is_server}
verify_outgoing = true
verify_server_hostname = true
performance {
raft_multiplier = 1
}
bind_addr = \"\{\{GetPrivateInterfaces | include \"network\" \"${private_network_ip_range}\" | attr \"address\"\}\}\"
Error: function "GetPrivateInterfaces" not defined
Example:
server.pkr.hcl
locals{
config_content=templatefile("consul-config.tpl", {
is_server = true
....
})
}
build{
provisioner "shell"{
inline = ["echo \"${local.config_content}\" > /etc/consul.d/consul.hcl"]
}
}