k2tf converts Kubernetes YAML manifests into Terraform HCL configuration files for seamless infrastructure as code integration.
Kubernetes YAML to Terraform HCL converter
This tool is designed for DevOps engineers and cloud security professionals who want to migrate or manage Kubernetes resources using Terraform. It simplifies the process of converting existing Kubernetes YAML files or live cluster objects into Terraform configurations, enabling better infrastructure as code practices and security automation.
Requires a working Golang build environment for building from source. The generated Terraform files are intended for use with the Terraform Kubernetes Provider, so users should be familiar with Terraform workflows. Using live cluster data conversion can streamline infrastructure as code adoption but ensure Kubernetes API access permissions are properly configured.
Download pre-built binary from the GitHub releases page
Install via Homebrew using: brew install k2tf
Use asdf plugin via asdf-k2tf for version management
Clone the repository: git clone https://github.com/sl1pm4t/k2tf.git
Build from source: cd k2tf && make build
Run tests with: make test
k2tf -f test-fixtures/service.yaml
Convert a single Kubernetes YAML file and output Terraform config to stdout
k2tf -f test-fixtures/service.yaml -o service.tf
Convert a single Kubernetes YAML file and write the output to a specified Terraform file
k2tf -f test-fixtures/
Convert all Kubernetes YAML files in a directory
kubectl get deployments -o yaml | ./k2tf -o deployments.tf
Fetch Kubernetes objects directly from a cluster and convert them to Terraform configuration