I have successfully deployed AKS Using Terragrunt through Atlantis, Now I want to set credentials to communicate with the Kubernetes API Server.
For that, I am setting up the KUBECONFIG Environment variable to authenticate with Kubernetes.
Below is the code that will run in Atlantis Container, so that we will have one-click deployment of pods or helm after setting credentials through Terraform code only.
resource "null_resource" "null" {
provisioner "local-exec" {
command = <<-EOT
echo "$(terraform output kube_config)" > ~/.kube/azurek8s # Storing kube config credential file for kube api server authentication
sed -i '1d;$d' ~/.kube/azurek8s # delete 1st and last line from output
EOT
}
provisioner "local-exec" {
command = "export KUBECONFIG=~/.kube/azurek8s" # setting up env variable for kubeconfig
}
provisioner "local-exec" {
command = "env"
}
}
After setting up the environment variable, I have added the env command to check whether actually environment variable is set or not.