51 lines
1.5 KiB
Terraform
51 lines
1.5 KiB
Terraform
![]() |
locals {
|
||
|
kubeconfig_name = "gke_${google_container_cluster.cluster.project}_${google_container_cluster.cluster.location}_${google_container_cluster.cluster.name}"
|
||
|
kubeconfig_yaml = yamlencode(local.kubeconfig)
|
||
|
kubeconfig = {
|
||
|
apiVersion = "v1"
|
||
|
kind = "Config"
|
||
|
preferences = {}
|
||
|
clusters = [
|
||
|
{
|
||
|
name = local.kubeconfig_name
|
||
|
cluster = {
|
||
|
server = "https://${google_container_cluster.cluster.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint}"
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
contexts = [
|
||
|
{
|
||
|
name = local.kubeconfig_name
|
||
|
context = {
|
||
|
cluster = local.kubeconfig_name
|
||
|
user = local.kubeconfig_name
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
current-context = local.kubeconfig_name
|
||
|
users = [
|
||
|
{
|
||
|
name = local.kubeconfig_name
|
||
|
user = {
|
||
|
exec = {
|
||
|
apiVersion = "client.authentication.k8s.io/v1beta1"
|
||
|
command = "gke-gcloud-auth-plugin"
|
||
|
provideClusterInfo = true
|
||
|
installHint = <<EOT
|
||
|
Install gke-gcloud-auth-plugin for use with kubectl by following
|
||
|
https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin
|
||
|
EOT
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
resource "local_file" "kubeconfig" {
|
||
|
content = local.kubeconfig_yaml
|
||
|
filename = "${path.module}/../../../output/kubeconfig/${var.name}.yaml"
|
||
|
file_permission = "0600"
|
||
|
directory_permission = "0755"
|
||
|
}
|