Skip to content

Provider doesn't properly setup when only given config_context value without config_path #1274

@mgarstecki

Description

@mgarstecki

Terraform Version, Provider Version and Kubernetes Version

Terraform version: v0.14.7
Kubernetes provider version: v2.2.0
Kubernetes version: v1.19

Affected Resource(s)

Terraform Configuration Files

provider "kubernetes" {
  config_context = "<a valid context name of your default kubeconfig>"
}

data "kubernetes_service" "kubernetes" {
  metadata {
    name      = "kubernetes"
    namespace = "default"
  }
}

Steps to Reproduce

  1. Have a proper Kubernetes context setup in your kubeconfig (no additional settings, especially nothing in KUBE_CONFIG_PATH)
  2. terraform apply

Expected Behavior

The datasource should have loaded properly from my context.

Actual Behavior

Terraform fails with the following output:

Error: Get "http://localhost/api/v1/namespaces/default/services/kubernetes": dial tcp [::1]:80: connect: connection refused

  on main.tf line 10, in data "kubernetes_service" "kubernetes":
  10: data "kubernetes_service" "kubernetes" {

Important Factoids

My client setup otherwise works, kubectl --context <a valid context name of your default kubeconfig> ... works.

I have no KUBE_CONFIG_PATH variable set, and this is intended: I expect the provider to pick up the location of the default Kubeconfig if none is set with KUBE_CONFIG_PATH/config_path, like other Kubernetes clients.

This impacts our setup since we tend to have different workstation setups in my team (MacOS vs Linux, user-wide config vs local ones, ...), and it is hard to find a convention to setup env vars or Terraform provider values in this case.

The Kubernetes provider seems to me to go against usual client behaviour by ignoring ~/.kube/config if no override is provided.
Just setting config_context without specifying the config file works on the helm provider for example.

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions