Back to rankings

jrhouston/tfk8s

Go

A tool for converting Kubernetes YAML manifests to Terraform HCL

terraformkubernetesconverteryamlhcl
Star Growth
Stars
1.1k
Forks
64
Weekly Growth
Issues
21
5001k
Jan 2023Mar 2024May 2025Jul 2026
ArtifactsGo Modulesgo get github.com/jrhouston/tfk8s
README

tfk8s Go Report Card tests


tfk8s is a tool that makes it easier to work with the Terraform Kubernetes Provider.

If you want to copy examples from the Kubernetes documentation or migrate existing YAML manifests and use them with Terraform without having to convert YAML to HCL by hand, this tool is for you.

Demo

Features

  • Convert a YAML file containing multiple manifests
  • Strip out server side fields when piping kubectl get $R -o yaml | tfk8s --strip

Install

go install github.com/jrhouston/tfk8s@latest

Alternatively, clone this repo and run:

make install

If Go's bin directory is not in your PATH you will need to add it:

export PATH=$PATH:$(go env GOPATH)/bin

Or you can install via brew for macOS/Linux:

brew install tfk8s

On macOS, you can also install via MacPorts:

sudo port install tfk8s

Usage

Usage of tfk8s:
  -f, --file string         Input file containing Kubernetes YAML manifests (default "-")
  -M, --map-only            Output only an HCL map structure
  -o, --output string       Output file to write Terraform config (default "-")
  -p, --provider provider   Provider alias to populate the provider attribute
  -s, --strip               Strip out server side fields - use if you are piping from kubectl get
  -Q, --strip-key-quotes    Strip out quotes from HCL map keys unless they are required.
  -V, --version             Show tool version

Examples

Create Terraform configuration from YAML files

tfk8s -f input.yaml -o output.tf

or, using pipes:

cat input.yaml | tfk8s > output.tf

input.yaml:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: test
data:
  TEST: test

✨✨ magically becomes ✨✨

output.tf:

resource "kubernetes_manifest" "configmap_test" {
  manifest = {
    "apiVersion" = "v1"
    "data" = {
      "TEST" = "test"
    }
    "kind" = "ConfigMap"
    "metadata" = {
      "name" = "test"
    }
  }
}

Use with kubectl to output maps instead of YAML

kubectl get ns default -o yaml | tfk8s -M
{
  "apiVersion" = "v1"
  "kind" = "Namespace"
  "metadata" = {
    "creationTimestamp" = "2020-05-02T15:01:32Z"
    "name" = "default"
    "resourceVersion" = "147"
    "selfLink" = "/api/v1/namespaces/default"
    "uid" = "6ac3424c-07a4-4a69-86ae-cc7a4ae72be3"
  }
  "spec" = {
    "finalizers" = [
      "kubernetes",
    ]
  }
  "status" = {
    "phase" = "Active"
  }
}

Convert a Helm chart to Terraform

You can use helm template to generate a manifest from the chart, then pipe it into tfk8s:

helm template ./chart-path -f values.yaml | tfk8s

Convert a directory tree of manifests to Terraform

You can use tfk8s in conjunction with find to convert an entire directory recursively:

find dirname/ -name '*.yaml' -type f -exec sh -c 'tfk8s -f {} -o $(echo {} | sed "s/\.[^.]*$//").tf' \;
Related repositories
bregman-arie/devops-exercises

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

PythonPyPIOtherdevopsaws
83.3k19.8k
hashicorp/terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

GoGo ModulesOthergraphinfrastructure-as-code
developer.hashicorp.com/terraform
49.3k10.5k
MichaelCade/90DaysOfDevOps

This repository started out as a learning in public project for myself and has now become a structured learning map for many in the community. We have 3 years under our belt covering all things DevOps, including Principles, Processes, Tooling and Use Cases surrounding this vast topic.

ShellOtherdevopskubernetes
90daysofdevops.com
29.6k6.8k
GoogleCloudPlatform/microservices-demo

Sample cloud-first application with 10 microservices showcasing Kubernetes, Istio, and gRPC.

GoGo ModulesApache License 2.0kubernetesgrpc
cymbal-shops.retail.cymbal.dev
20.6k10.2k
mikefarah/yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML, HCL and properties processor

GoGo ModulesMIT Licenseyaml-processoryaml
mikefarah.gitbook.io/yq/
15.7k797
budtmo/docker-android

Android in docker solution with noVNC supported and video recording

PythonPyPIOtherdocker-androidandroid
15.6k1.7k
GoogleCloudPlatform/terraformer

CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code

GoGo ModulesApache License 2.0cloudterraform
14.6k1.8k
coder/coder

Secure environments for developers and their agents

GoGo ModulesGNU Affero General Public License v3.0remote-developmentdevelopment-environment
coder.com
13.9k1.4k
semaphoreui/semaphore

Modern UI and powerful API for Ansible, Terraform/OpenTofu/Terragrunt, PowerShell and other DevOps tools.

GoGo ModulesMIT Licenseansibledevops
semaphoreui.com
13.9k1.3k
infracost/infracost

Cloud cost intelligence for engineers, AI coding agents, and CI/CD 💰📉 Shift FinOps Left!

GoGo ModulesApache License 2.0terraformcost-estimation
infracost.io
12.4k679
hashicorp/terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.

GoGo ModulesMozilla Public License 2.0terraformterraform-provider
registry.terraform.io/providers/hashicorp/aws
11k10.3k
gruntwork-io/terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.

GoGo ModulesMIT Licenseterraformdevops
terragrunt.com
9.7k1.2k