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
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
.