Intro
I'm having an issue with the Kubernetes provider in Terraform. When I configure it with my local ~/.kube/config
, it works. But when I try to configure it with the outputs from my cluster creation module, it mysteriously tries to act as a user named 'client' who has no permissions within the cluster, and terraform plan
fails.
My code (outputs from cluster creation)
# module 'cluster'
output "cluster_endpoint" {
value = google_container_cluster.general_purpose.endpoint
}
output "cluster_client_certificate" {
value = base64decode(google_container_cluster.general_purpose.master_auth[0].client_certificate)
}
output "cluster_client_key" {
value = base64decode(google_container_cluster.general_purpose.master_auth[0].client_key)
sensitive = true
}
output "cluster_ca_certificate" {
value = base64decode(google_container_cluster.general_purpose.master_auth[0].cluster_ca_certificate)
}
What works
# module 'ingress'
provider "kubernetes" {
config_path = "~/.kube/config"
}
data "kubernetes_namespace" "namespace_default" {
metadata {
name = "default"
}
}
What doesn't work
# module 'ingress'
provider "kubernetes" {
host = "https://${var.cluster_endpoint}"
client_certificate = var.cluster_client_certificate
client_key = var.cluster_client_key
cluster_ca_certificate = var.cluster_ca_certificate
}
data "kubernetes_namespace" "namespace_default" {
metadata {
name = "default"
}
}
The Error
$ terraform plan
╷
│ Error: namespaces "default" is forbidden: User "client" cannot get resource "namespaces" in API group "" in the namespace "default"
│
│ with module.ingress.data.kubernetes_namespace.namespace_default,
│ on modules/ingress/main.tf line 42, in data "kubernetes_namespace" "namespace_default":
│ 42: data "kubernetes_namespace" "namespace_default" {
│
╵
I haven't been able to figure out where this user named 'client' is set. I can replicate the error by running the command using the --as client
argument in kubectl. (The same command works if I omit this argument.)
$ kubectl get namespace default --as client
Error from server (Forbidden): namespaces "default" is forbidden: User "client" cannot get resource "namespaces" in API group "" in the namespace "default"
I'm under the impression that there should be no "named" user involved, because I am working with certificate-based authentication. But somehow, a username is working its way into the command used by the Kubernetes provider.
I appreciate any suggestions!