Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubectl missing form Terraform Cloud

I am using terraform cloud to provision some k8s infrastructure .

The issue i am facing is as terraform provider for kubernetes doesn't have the flexibility of yaml file . i need to run some yaml files using kubectl apply This was okay when we run from local machine but when its from Terraform cloud it errors that

kubectl is not installed 

Is there a way to solve this ?

possible install kubectl on terraform cloud

Thanks in advance

like image 716
Lib Avatar asked Mar 27 '26 17:03

Lib


1 Answers

You can download the kubectl binary using a null_resource with the local_exec provisioner:

resource "null_resource" "custom" {
  # change trigger to run every time
  triggers = {
    build_number = "${timestamp()}"
  }

  # download kubectl
  provisioner "local-exec" {
    command = "curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl"
  }

  # run kubectl
  provisioner "local-exec" {
    command = "./kubectl apply -f deployment.yaml"
  }
}

Of course you also have to provide the target settings/credentials for kubectl, but that depends on your cluster provider, for example on AKS you would run az aks get-credentials before using kubectl.

like image 168
Markus Dresch Avatar answered Mar 30 '26 06:03

Markus Dresch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!