<p>Terraform Kubernetes doesn't allow use of anything other than <code>apiVersion: v1</code>. However I wanted to work around that by using the <code>null_resource</code> provisioner to run <code>kubectl apply -f ...</code> and <code>kubectl delete -f ...</code> (with <code>when = "destroy"</code>).</p>

<p>I've attempted to get this to work using the kubernetes apply EOF pattern, but haven't managed it just yet.</p>

<p>Here is where I've gotten to but it seems the <code>|</code> is an illegal char.</p>

<p>Also hoping I could pull the yaml string out into a multiline variable so I don't have to repeat it in the null resource.</p>

<pre><code>resource "null_resource" "res_name" {
  provisioner {
    command = &lt;&lt;EOF | kubectl apply -f -
      apiVersion: extensions/v1beta1
      kind: Ingress
      metadata:
        name: some-ingress-name
        annotations:  
          kubernetes.io/ingress.class: nginx
      spec:
        rules:
        - host: subdomain.example.com
          http:
            paths:
            - backend:
                serviceName: some-cluster-ip-service
                servicePort: 80
  }

  provisioner {
    when = "destroy"

    command = &lt;&lt;EOF | kubectl delete -f -
      apiVersion: extensions/v1beta1
      kind: Ingress
      metadata:
        name: some-ingress-name
        annotations:  
          kubernetes.io/ingress.class: nginx
      spec:
        rules:
        - host: subdomain.example.com
          http:
            paths:
            - backend:
                serviceName: some-cluster-ip-service
                servicePort: 80
  }
}
</code></pre>

<p>There were some bugs in your code.</p>

<ul>
<li>You missed the ending <code>EOF</code> for the <code>&lt;&lt;EOF</code> (<a href="https://www.terraform.io/docs/configuration/syntax.html#terraform-syntax" rel="noreferrer">"here-doc" syntax</a>)</li>
<li>A shell can't start with the pipe (<code>|</code>) command. The <a href="https://www.terraform.io/docs/provisioners/local-exec.html" rel="noreferrer"><code>local-exec</code> provisioner</a> runs the command in the local shell. Therefore use the <a href="https://github.com/hashicorp/terraform/issues/13420#issuecomment-294858906" rel="noreferrer"><code>&lt;&lt;EOF</code> stdin trick from the Github issue comment</a>. Thanks for the hint. Didn't know this, too.</li>
</ul>

<p>That code works on my side:</p>

<pre><code>resource "null_resource" "res_name" {
  provisioner "local-exec" {
    command = "kubectl apply -f - &lt;&lt;EOF\n${var.ingress_yaml}\nEOF"
  }

  provisioner "local-exec" {
    when = "destroy"
    command = "kubectl delete -f - &lt;&lt;EOF\n${var.ingress_yaml}\nEOF"
  }
}

variable "ingress_yaml" {
  default = &lt;&lt;EOF
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: some-ingress-name
      annotations:
        kubernetes.io/ingress.class: nginx
    spec:
      rules:
      - host: subdomain.example.com
        http:
          paths:
          - backend:
              serviceName: some-cluster-ip-service
              servicePort: 80
    EOF
}
</code></pre>

<p>I suggest to read in the YAML configuration from a file, instead. Then you can get YAML syntax highlighting and errors shown in your IDE.
Use either</p>

<ul>
<li><a href="https://www.terraform.io/docs/providers/local/d/file.html" rel="noreferrer"><code>data "local_file"</code></a> or </li>
<li><a href="https://www.terraform.io/docs/providers/template/d/file.html" rel="noreferrer"><code>data "template_file"</code></a>, when you want to change something in the
file.</li>
</ul>
