Wrong indentation in yaml file inserted into terraform template

Hello,

I’m trying to use the terraform template to copy some files to a vm (the template is actually a cloud-init config file). The issue that I’m currently having is that the indentation is not correct and I’m not sure how I’m supposed to solve this.
This is a snippet of cloud-init template:

write_files:
  - content: |
      ${haproxy-deploy}
    path: /tmp/haproxy-deploy.yaml

And this is the relevant bit in main.tf:

data "template_cloudinit_config" "work" {
        gzip = false
        base64_encode = false
        part {
                filename = "cloud-init.cfg"
                content_type = "text/cloud-config"
                content = templatefile("${path.module}/files/cloud_init_ub2004.tpl", {
                        root_ssh_key = file("${path.module}/files/id_ed25519.pub")
                        haproxy-deploy = file("${path.module}/files/haproxy-deploy.yaml")
                        haproxy-ingress = file("${path.module}/files/haproxy-ingress.yaml")
                        dockerconfigjson = file("${path.module}/files/dockerconfigjson")

haproxy-deploy.yaml is a simple yaml, a kube manifest.
And this is what I get when the template is rendered:

            write_files:
             - content: |
                 apiVersion: v1
           kind: Secret
           metadata:
             name: ejobs-cert
             namespace: code-server
           data:

So kind, metadata etc. need to be on the same level with apiVersion, but only the first line is correctly indented. Any ideas how I can force this to work correctly?