alessiodionisi / terraform-provider-k0s

Terraform provider to create and manage k0s Kubernetes clusters, using embedded k0sctl
https://registry.terraform.io/providers/alessiodionisi/k0s
Apache License 2.0
23 stars 8 forks source link

Get access data (kubeconfig or equivalent) #79

Closed aronwolf90 closed 1 year ago

aronwolf90 commented 1 year ago

Is there any way to get the access data? (E.g. cluster_ca_certificate, client_certificate and client_key) . If it is not the case, then I am willing to submit a pull request with a data source (https://developer.hashicorp.com/terraform/plugin/framework/data-sources).

thechubbypanda commented 1 year ago

Seconded, how do you utilise the kubeconfig output? Say for the kubernetes provider.

alessiodionisi commented 1 year ago

In my projects I'm decoding the yaml in a local variable:

locals {
  kubeconfig = yamldecode(k0s_cluster.cluster.kubeconfig)
}

and I'm using it in the provider configurations, for example:

provider "kubernetes" {
  host                   = local.kubeconfig.clusters[0].cluster.server
  cluster_ca_certificate = base64decode(local.kubeconfig.clusters[0].cluster.certificate-authority-data)
  client_certificate     = base64decode(local.kubeconfig.users[0].user.client-certificate-data)
  client_key             = base64decode(local.kubeconfig.users[0].user.client-key-data)
}

Let me know if this works for you 😄

aronwolf90 commented 1 year ago

Ah thanks. Yes It worked for me :)