tfo2kc: TerraForm Output 2 KubeConfig
A CLI tool which updates ~/.kube/config with relevant cluster, user and context information sourced from single kubeconfig string extracted from output of Terraform-compatible tool (Terragrunt/OpenTofu). It is useful in scenarios where some TF provider bootstraps a Kubernetes cluster and initial admin kubeconfig file is retrievable as output.
Some benefits:
- single command to prepare terminal to use fresh k8s cluster after TF finishes boostrap:
TF->tfo2kc->kubectl - no need to manage many paths in environmental variable
KUBECONFIG- all config entries can be stored in single~/.kube/configso any tool can consume them - automatic rename of cluster, user and context objects, which tend to be all "default" when coming from many common k8s bootstrap tools; this is especially important when merging many kubeconfigs
- support for any source tool which behaves like
terraform output -json - automatic backup of
~/.kube/config tfo2kc.iniconfig stored in TF directory for context dependent translation
Installation
pipx install tfo2kc
Usage
--help
Usage: tfo2kc [OPTIONS]
tfo2kc: Terraform/Terragrunt/openTofu Output 2 KubeConfig: CLI to merge
kubeconfig obtained from TF output as string into ~/.kube/config
Options:
-t, --terraform-binary TEXT Terraform-compatible CLI (terraform, tofu,
terragrunt).
-o, --output-key TEXT Terraform output key (dot-path) for the
kubeconfig string.
-c, --cluster-name TEXT Name under which to store the cluster in
kubeconfig.
-u, --user-name TEXT Username in kubeconfig (defaults to same as
cluster name).
-x, --context-name TEXT Context name (defaults to <cluster>-ctx).
-k, --kubeconfig TEXT Path to existing kubeconfig file (default
~/.kube/config).
-d, --tf-dir TEXT Directory where Terraform/terragrunt/tofu lives
(default cwd).
-f, --config-file TEXT INI file name or path in TF dir for defaults;
default tfo2kc.ini.
--help Show this message and exit.
Direct invocation
tfo2kc -t terraform -o myKubeConfig -c my-cluster -d /path/to/terraform/dir
tfo2kc -t terragrunt -o myKubeConfig -c my-cluster -d /path/to/terraform/dir
tfo2kc -t /path/to/opentofu -o myKubeConfig -c my-cluster -d /path/to/terraform/dir
Running in current directory
tfo2kc -o myKubeConfig -c my-cluster
Running in another directory
tfo2kc -d /path/to/other/dir -o myKubeConfig -c other-cluster
Using an INI file
Place a tfo2kc.ini file alongside your Terraform files:
[default]
terraform_binary = terraform
output_key = myKubeConfig
cluster_name = my-cluster
user_name = my-user
context_name = my-context
kubeconfig_path = ~/.kube/config
Then run:
tfo2kc -d /path/to/terraform/dir
Example usage in Terraform
resource "k0s_cluster" "example" {
# ... cluster setup ...
}
output "myKubeConfig" {
value = k0s_cluster.example.kubeconfig
sensitive = true
}
tool invocation:
tfo2kc -d . -o myKubeConfig -c example-cluster
Metadata
Release files for tfo2kc 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tfo2kc-0.2.1.tar.gz | 5.1 kB | Without provenance | Details for tfo2kc-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tfo2kc-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for tfo2kc-0.2.1-py3-none-any.whl |
Total release size: 11.4 kB
Release files / tfo2kc-0.2.1.tar.gz
| Download URL | tfo2kc-0.2.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a5a4364a57bc0279ea9cc20372b4ff31e445a7cd268ecbb8a932c70921c1226
|
|
BLAKE2b-256 checksum How to use checksums |
2fd40ecf9ddfe721e8afc35fce1b3d6f80897c93af3ba159c072a636e6f54a7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.14.5 HTTPX/0.28.1
|
Release files / tfo2kc-0.2.1-py3-none-any.whl
| Download URL | tfo2kc-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f75b87d1a44c1b72d455bce26aa77fb1e658d27e5c5ec40f169e297a626278c
|
|
BLAKE2b-256 checksum How to use checksums |
196a05a0e5c96d5a22083668a05922aaba612982135178920077f2a996824cbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.14.5 HTTPX/0.28.1
|
Security for tfo2kc 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.