<p>I have the following, relatively complicated piece of YAML:</p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: aws-auth
  namespace: kube-system
data:
  mapRoles: |
    - rolearn: ${aws_iam_role.tf-eks-node.arn}
      username: system:node:{{EC2PrivateDNSName}}
      groups:
        - system:bootstrappers
        - system:nodes
</code></pre>

<p>I now want to translate this into a Terraform-Kubernetes compatible resource, which consists exclusively of String, Lists and Maps. How do I do this? 
I found an example of how a LimitRange would look <a href="https://www.terraform.io/docs/providers/kubernetes/guides/getting-started.html" rel="nofollow noreferrer">here</a> using hyphens to signify a list:</p>

<pre><code>resource "kubernetes_limit_range" "example" {
    metadata {
        name = "terraform-example"
    }
    spec {
        limit {
            type = "Pod"
            max {
                cpu = "200m"
                memory = "1024M"
            }
        }
        limit {
            type = "PersistentVolumeClaim"
            min {
                storage = "24M"
            }
        }
        limit {
            type = "Container"
            default {
                cpu = "50m"
                memory = "24M"
            }
        }
    }
}
</code></pre>

<p>My current try for the mapRoles block is as follows:</p>

<pre><code>mapRole { rolearn = "${aws_iam_role.tf-eks-node.arn}"
      username = "system:node:{{EC2PrivateDNSName}}"
      groups = ["system:bootstrappers","system:nodes"]}
</code></pre>

<p>This is not correct because mapRoles is a list (because its singular element is a list element as demonstrated by the hyphen); but if it is a list, and everything after the hyphen is the list element, what is the list title?</p>

<p>using the idea mentioned in an answer, I tried to put the metadata block in a data-block beforehand:</p>

<pre><code>data "template_file" "map_roles" {
  template = &lt;&lt;EOF
- rolearn: ${var.arn}
  username: system:node:{{EC2PrivateDNSName}}
  groups:
    - system:bootstrappers
    - system:nodes
EOF

  vars {
    arn = "${var.kube-arn}"
  }
}

resource "kubernetes_config_map" "aws_auth" {
  metadata {
    name = "aws-auth"
    namespace = "kube-system"
  }
  data {
    mapRoles = "${data.template_file.map_roles.template}"
  } 
}
</code></pre>

Torsten N.
<p>Managed to make it work with some changes to David Maze's answer:</p>

<pre><code>resource "kubernetes_config_map" "aws_auth" {
  metadata {
    name = "aws-auth"
    namespace = "kube-system"
  }
  data {
    mapRoles = &lt;&lt;EOF
- rolearn: ${var.kube-arn}
  username: system:node:{{EC2PrivateDNSName}}
  groups:
    - system:bootstrappers
    - system:nodes
EOF
  } 
}
</code></pre>

<p>The idea of putting the |-input into an EOF-block is what I was missing. Terraform can resolve variable input directly in that block, so I didn't even need a data block to set the template up first.</p>
