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.
Each local-exec
will execute in its own shell environment, so there is no persistence between the second and third executions of your local-exec
.
To set environment variables for your local-exec
, you should use environment:
provisioner "local-exec" {
command = "env"
environment = {
KUBECONFIG = "~/.kube/azurek8s"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With