Hi@akhtar,
You can use data source in Terraform. This data source provides a mechanism for listing the names of all available namespaces in a Kubernetes cluster. You can also go through the below code.
provider "kubernetes" {
config_context_cluster = "minikube"
}
data "kubernetes_all_namespaces" "allns" {}
output "all-ns" {
value = data.kubernetes_all_namespaces.allns.namespaces
}
Execute this code in your terraform platform, you will get your output.
C:\Users\NADIM AKTHAR\Desktop\terraform\kuberenetes>terraform apply
data.kubernetes_all_namespaces.allns: Refreshing state...
kubernetes_namespace.example: Refreshing state... [id=my-first-namespace]
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
all-ns = [
"default",
"kube-node-lease",
"kube-public",
"kube-system",
"my-first-namespace",
]