I'm trying to use kubernetes-alpha provider in Terraform, but I have "Failed to construct REST client" error message. I'm using tfk8s to convert my yaml file to terraform code.
I make the seme declaration for the provider than kubernetes, and my kubernetes provider work correctely
provider "kubernetes-alpha" {
host = "https://${data.google_container_cluster.primary.endpoint}"
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(data.google_container_cluster.primary.master_auth[0].cluster_ca_certificate)
}
provider "kubernetes" {
host = "https://${data.google_container_cluster.primary.endpoint}"
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(data.google_container_cluster.primary.master_auth[0].cluster_ca_certificate)
}
resource "kubernetes_manifest" "exemple" {
provider = kubernetes-alpha
manifest = {
# result of tfk8s
}
}
somebody can help ?
After some digging, I found that this resource requires a running kubernetes instance and config before the terraform plan will work properly. Best stated in github here: https://github.com/hashicorp/terraform-provider-kubernetes-alpha/issues/199#issuecomment-832614387
Basically, you have to have two steps to first terraform apply your main configuration to stand up kubernetes in your cloud, and then secondly terraform apply the CRD resource once that cluster has been established.
EDIT: I'm still trying to learn good patterns/practices for managing terraform config and found this pretty helpful. How to give a .tf file as input in Terraform Apply command?. I ended up just keeping the cert manager CRD as a standard kubernetes manifest yaml that I apply per-cluster with other application helm charts.