nutanix / terraform-provider-nutanix

Terraform Nutanix Provider
https://www.terraform.io/docs/providers/nutanix/
Mozilla Public License 2.0
95 stars 111 forks source link

How Can I use data source nutanix_karbon_cluster_kubeconfig in the Null_Resource with kubectl command to use kubeconfig for authentication #614

Open ashishreddyaleti opened 1 year ago

ashishreddyaleti commented 1 year ago

I have below clode

data "nutanix_karbon_cluster_kubeconfig" "kubeconfig" { karbon_cluster_name = nutanix_karbon_cluster.karbon.name }

resource "null_resource" "get_key" { provisioner "local-exec" { interpreter = [ "/bin/bash", "-c" ] working_dir = "${path.module}" command = "export PODNAME=$(kubectl get po -l name=jump -ojson | jq -r '.items[0].metadata.name') && kubectl cp default/$(POD_NAME):etc/kubernetes/ssl/apiserver-key.pem sa-old.pub" } }

In the above How can I use kubeconfig to authenticate for Kubectl command.

What i Have tried is

resource "null_resource" "get_key" { provisioner "local-exec" { interpreter = [ "/bin/bash", "-c" ] working_dir = "${path.module}" command = "export PODNAME=$(kubectl get --kubeconfig='${data.nutanix_karbon_cluster_kubeconfig.kubeconfig}' po -l name=jump -ojson | jq -r '.items[0].metadata.name') && kubectl cp --kubeconfig='${data.nutanix_karbon_cluster_kubeconfig.kubeconfig}' default/$(POD_NAME):etc/kubernetes/ssl/apiserver-key.pem sa-old.pub" } }

It give me below error Error: Invalid template interpolation value │ │ on resource.tf line 186, in resource "null_resource" "get_key": │ 186: command = "export PODNAME=$(kubectl get --kubeconfig='${data.nutanix_karbon_cluster_kubeconfig.kubeconfig.access_token}' po -l name=jump -ojson | jq -r '.items[0].metadata.name') && kubectl cp --kubeconfig='${data.nutanix_karbon_cluster_kubeconfig.kubeconfig}' default/$(POD_NAME):etc/kubernetes/ssl/apiserver-key.pem sa-old.pub" │ ├──────────────── │ │ data.nutanix_karbon_cluster_kubeconfig.kubeconfig is object with 7 attributes │ │ Cannot include the given value in a string template: string required.

How can I use the kubeconfig for authentication with Kubectl command ?