Creating local configuration files with Terraform templating
Unfortunately there’s no nice way of producing templates locally with Terraform, however there is a way of doing so.
Use the data provider to specify the local template and the variables required
| data "template_file" "config" {
| template = "${file("file.yaml.tpl")}"
| vars {
| foo = "variable1"
| bar = "variable2"
| }
|}
We then create a null resource and use the local-exec provider to create the template, we also use a trigger so any changes to data.template_file.config reruns the local-exec provisioner.
resource "null_resource" "template" {
triggers { template = "${data.template_file.config.rendered}" }
provisioner "local-exec" { command = "echo \"${data.template_file.config-eu.rendered}\" > config-eu.yaml" } }










