<p>I am using the <a href="https://www.terraform.io/docs/providers/kubernetes/index.html" rel="nofollow noreferrer">Kubernetes Provider</a> to describe services/pods in Terraform.</p>

<p>It can get confusing using the Hashicorp Configuration Language to define <a href="https://www.terraform.io/docs/providers/kubernetes/r/pod.html" rel="nofollow noreferrer">kubernetes_pod</a> or <a href="https://www.terraform.io/docs/providers/kubernetes/r/service.html" rel="nofollow noreferrer">kubernetes_service</a> resources because the Kubernetes documentation describes everything in YAML which it means you need to translate it into HCL.</p>

<p>Is it possible to define pods as YAML and use them with <code>kubernetes_pod</code> and <code>kubernetes_service</code> resources as templates?</p>

<p>While Terraform normally uses HCL, this is a superset of JSON (much like YAML itself) so <a href="https://www.terraform.io/docs/configuration/syntax.html#json-syntax" rel="nofollow noreferrer">can also read JSON</a>.</p>

<p>One possible option would be to take the YAML examples you already have and convert them into JSON and then use Terraform on those.</p>

<p>Unfortunately, that's unlikely to work because keywords are likely to be different for how Terraform is expecting things so you'd need to write something to do some basic translation of the input YAML to a Terraform resource JSON. At this point, it'd probably be worth just adding HCL output to the conversion so your outputted Terraform config is more readable if you ever intend to keep the Terraform config around instead of just one shot converting and applying the config.</p>

<p>The benefit of doing things this way would be that you have a reusable Kubernetes config that could be ran using <code>kubectl</code> or other tools but gives you the power of Terraform's lifecycle management, being able to plan changes and integration with non Kubernetes parts of your infrastructure (such as setting up instances to run the Kubernetes cluster on).</p>

<p>I've not used it much but I believe <a href="https://github.com/kubernetes/kops" rel="nofollow noreferrer">Kops</a> will allow you to keep pod/service config in typical Kubernetes YAML files but can then use Terraform to manage the configuration and even allows you to output the Terraform configuration so you can run it outside of Kops itself.</p>
