How to deploy a Helm chart on AKS cluster with Terraform's local-exec?

7/26/2018

I have created an AKS cluster on Azure using Terraform.

I have also set up my local workstation to be able to use kubectl, Helm and azurecli.

I am trying to deploy a Helm chart via Terraform after the successful cluster creation, with the following code:

resource "local_file" "local-config-file" {
  content  = "${azurerm_kubernetes_cluster.k8s.kube_config_raw}"
  filename = "${path.module}/${var.cluster_name}.conf"
}

resource "null_resource" "set_kubeconfig" {
  provisioner "local-exec" {
    # working_dir = ""
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "export KUBECONFIG=${path.module}/${var.cluster_name}.conf"
  }
}

resource "null_resource" "helm_drone" {
  provisioner "local-exec" {
    # working_dir = ""
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "helm upgrade --install drone stable/drone"
  }
  depends_on = ["null_resource.set_kubeconfig"]
}

The local-config-file is executed and the file is created correctly.

However, Terraform reports that set_kubeconfig and helm_drone are executed and completed,

null_resource.set_kubeconfig: Creating...
null_resource.set_kubeconfig: Provisioning with 'local-exec'...
local_file.local-config-file: Creation complete after 0s (ID: d4c1df0df32052fb47437107957cb88b14d0d0d3)
null_resource.set_kubeconfig (local-exec): Executing: ["C:/Program Files/Git/git-bash.exe" "export KUBECONFIG=C:\\Users\\k.demiris\\Documents\\Projects\\a2\\tfcluster/k8s.conf"]
null_resource.set_kubeconfig: Creation complete after 1s (ID: 2649854281565879558)
null_resource.helm_drone: Creating...
null_resource.helm_drone: Provisioning with 'local-exec'...
null_resource.helm_drone (local-exec): Executing: ["C:/Program Files/Git/git-bash.exe" "helm upgrade --install drone stable/drone"]
null_resource.helm_drone: Creation complete after 0s

but when I check with echo $KUBECONFIG and helm ls I can see that nothing had happened.

I am using Terraform on a Windows10 PC, so I am using git-bash as the interpreter.

Does anyone have any experience with such a case?

EDIT

I tried this but didn't work:

resource "null_resource" "kubeconfig_and_helm" {
  provisioner "local-exec" {
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "export KUBECONFIG=${path.module}/${var.cluster_name}-test.conf && helm upgrade --install drone stable/drone"
  }
}

and this...and also did not work:

resource "null_resource" "config_helm" {
  provisioner "local-exec" {
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = <<EOT
    export KUBECONFIG=${path.module}/${var.cluster_name}.conf && \
    helm upgrade --install drone stable/drone
EOT
  }
}
-- Kostas Demiris
git-bash
kubernetes-helm
terraform

0 Answers