tfo2kc: Terraform/Terragrunt/openTofu Output 2 KubeConfig: CLI to merge kubeconfig obtained from TF output as string into ~/.kube/config
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tfo2kc-0.2.0.tar.gz.
File metadata
- Download URL: tfo2kc-0.2.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.14.4 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d98c6cc45187c984fb61a825434ff0b45719dc33edd2a50c43ca30c164904a52
|
|
| MD5 |
7c34c4408b2b6ec4b0e8f99f10b809a8
|
|
| BLAKE2b-256 |
e5efd535ade9227771931fa35174c5556f45bf72317edfb1ef2d15b815fc32bf
|
File details
Details for the file tfo2kc-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tfo2kc-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.14.4 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3d552e040bb96fba4ae7c7989096b12058b34d81043a2e977d30f7d8cc5fb04
|
|
| MD5 |
40e0b7d8ead71354be33543b4375b2c8
|
|
| BLAKE2b-256 |
820ca06e9851dd5cc85602889b73c88fd0d6074cc651866087fdb8bc7864c97d
|