Answers: <p>I don't know of a way to get Terraform to output to YAML but if you have access to the k8 cluster you can easily get the YAML for a deployment/pod. See this existing SO <a href="https://stackoverflow.com/questions/43941772/get-yaml-for-deployed-kubernetes-services">answer</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-05-06T14:33:14.360Z
Answers: `-o yaml` adds a lot of stuff not part of the original Terraform HCL.
Answers: Evan Carroll
Answers: CC BY-SA 4.0
Answers: 2023-05-06T10:28:58.883Z
Answers: 2023-05-06T10:28:58.883Z
Answers: Levi
Answers: <blockquote>
  <p>Is it possible to have the terraform provider for Kubernetes output to a directory or in some form the YAML that it is sending to kubernetes?</p>
  </blockquote>
  <p>You can do this with a combination of a <a href="https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file" rel="nofollow noreferrer">file</a> provider and the <a href="https://developer.hashicorp.com/terraform/language/functions/yamlencode" rel="nofollow noreferrer"><code>yamlencode()</code></a> function.</p>
  <p>Let's say you have a <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment_v1" rel="nofollow noreferrer"><code>kubernetes_deployment_v1</code></a> and you want to write the yaml description of it to a file:</p>
  <pre><code>resource &quot;kubernetes_deployment_v1&quot; &quot;this&quot; {
    ...
  }
  
  resource &quot;local_file&quot; &quot;that&quot; {
     content = yamlencode(kubernetes_deployment_v1.this.spec)
     filename = &quot;${path.module}/deployment_spec.yaml&quot;
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2023-05-07T04:15:11.510Z
Answers: 2023-05-07T04:15:11.510Z
Answers: Bruce Becker
Body: <p>Currently I have a deployment of an applicationn done with HCL in Terraform. Is it possible to have the terraform provider for Kubernetes output to a directory or in some form the YAML that it is sending to kubernetes?</p>
  
Tags: <kubernetes><terraform>
Title: Is there a way to migrate from HCL with the Terraform provider to YAML?
UserDisplayName: Evan Carroll
ThreadText: # Is there a way to migrate from HCL with the Terraform provider to YAML?
  
  (Asked by: username_0 on 2023-04-28)
  
  Currently I have a deployment of an applicationn done with HCL in Terraform. Is it possible to have the terraform provider for Kubernetes output to a directory or in some form the YAML that it is sending to kubernetes?
  
  **Tags:** kubernetes, terraform
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2023-05-06. Score: 0
  
  I don't know of a way to get Terraform to output to YAML but if you have access to the k8 cluster you can easily get the YAML for a deployment/pod. See this existing SO [answer](https://stackoverflow.com/questions/43941772/get-yaml-for-deployed-kubernetes-services).
  
  > **Comments:**
  > **username_0**: `-o yaml` adds a lot of stuff not part of the original Terraform HCL.  
  
  ---
  
  ### Answer by username_2 on 2023-05-07. Score: 0
  
  > Is it possible to have the terraform provider for Kubernetes output to a directory or in some form the YAML that it is sending to kubernetes?
  
  You can do this with a combination of a [file](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) provider and the [`yamlencode()`](https://developer.hashicorp.com/terraform/language/functions/yamlencode) function.
  
  Let's say you have a [`kubernetes_deployment_v1`](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/deployment_v1) and you want to write the yaml description of it to a file:
  
  ```
  resource "kubernetes_deployment_v1" "this" {
    ...
  }
  
  resource "local_file" "that" {
     content = yamlencode(kubernetes_deployment_v1.this.spec)
     filename = "${path.module}/deployment_spec.yaml"
  }
  
  ```
  
  
  ---
  
  