siderolabs / terraform-provider-talos

Mozilla Public License 2.0
136 stars 17 forks source link

resource talos_cluster_kubeconfig host points to localhost #187

Closed rotilho closed 2 months ago

rotilho commented 3 months ago

I attempted to change from the talos_cluster_kubeconfig data to resource however the host is incorrect, it points to localhost.

Original (works):

data "talos_cluster_kubeconfig" "home" {
  depends_on = [
    talos_machine_bootstrap.home
  ]
  client_configuration = talos_machine_secrets.home.client_configuration
  node                 = talos_machine_configuration_apply.home_a.node
}

New:

resource "talos_cluster_kubeconfig" "home" {
  depends_on = [
    talos_machine_bootstrap.home
  ]
  client_configuration = talos_machine_secrets.home.client_configuration
  node                 = talos_machine_configuration_apply.home_a.node
}

Output:

Error: Get "http://localhost/api/v1/namespaces/hub/endpoints/solar-panel-inverter": dial tcp [::1]:80: connect: connection refused
│ 
│   with module.solar_panel_inverter.kubernetes_endpoints.endpoint,
│   on modules/endpoint/main.tf line 1, in resource "kubernetes_endpoints" "endpoint":
│    1: resource "kubernetes_endpoints" "endpoint" {
frezbo commented 3 months ago

this is nothing on the provider side, you might have kubeconfig environment variable exported, or the resource accessing some other kubeconfig

rotilho commented 3 months ago

My kubeconfig points to the correct server however I'm directly setting up the provider with talos_cluster_kubeconfig so in my understanding it should work regardless of my env.

provider "kubernetes" {
  host = talos_cluster_kubeconfig.home.kubernetes_client_configuration.host
  cluster_ca_certificate = base64decode(talos_cluster_kubeconfig.home.kubernetes_client_configuration.ca_certificate)

  client_key = base64decode(talos_cluster_kubeconfig.home.kubernetes_client_configuration.client_key)
  client_certificate = base64decode(talos_cluster_kubeconfig.home.kubernetes_client_configuration.client_certificate)
}

The only difference is the data to resource change. If I revert back to data it works totally fine

frezbo commented 3 months ago

could you do a terraform state show talos_cluster_kubeconfig.home and see what it returns?

rotilho commented 3 months ago

I'm really confused. I rolled everything back and then bumped the Talos provider to 0.6.0-alpha.1, but the error still occurred. So, I decided to add the resource back in (and apply it using target) just to check the resource content. The content looked fine, so I applied it to the whole project, and surprisingly, it worked.

I'm not sure what the issue was, but it's gone now.

walnuss0815 commented 1 month ago

I had the same issue and managed to fix it using a moved block. In your case it should look like the following:

moved {
  from = data.talos_cluster_kubeconfig.home
  to   = talos_cluster_kubeconfig.home
}