diff --git a/kubernetes/provider.go b/kubernetes/provider.go index 3245dbd647..2b40cbe872 100644 --- a/kubernetes/provider.go +++ b/kubernetes/provider.go @@ -76,6 +76,12 @@ func Provider() *schema.Provider { Optional: true, Description: "A list of paths to kube config files. Can be set with KUBE_CONFIG_PATHS environment variable.", }, + "config_path": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", ""), + Description: "Path to the kube config file, defaults to ~/.kube/config", + }, "config_context": { Type: schema.TypeString, Optional: true, @@ -263,7 +269,10 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error) loader := &clientcmd.ClientConfigLoadingRules{} configPaths := []string{} - if v, ok := d.Get("config_paths").([]string); ok && len(v) > 0 { + + if v, ok := d.Get("config_path").(string); ok && v != "" { + configPaths = []string{v} + } else if v, ok := d.Get("config_paths").([]string); ok && len(v) > 0 { configPaths = v } else if v := os.Getenv("KUBE_CONFIG_PATHS"); v != "" { // NOTE we have to do this here because the schema @@ -281,7 +290,12 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error) log.Printf("[DEBUG] Using kubeconfig: %s", path) expandedPaths = append(expandedPaths, path) } - loader.Precedence = expandedPaths + + if len(expandedPaths) == 1 { + loader.ExplicitPath = expandedPaths[0] + } else { + loader.Precedence = expandedPaths + } ctxSuffix := "; default context" diff --git a/kubernetes/provider_test.go b/kubernetes/provider_test.go index 3015b250e2..41487f4456 100644 --- a/kubernetes/provider_test.go +++ b/kubernetes/provider_test.go @@ -73,7 +73,7 @@ func TestProvider_configure(t *testing.T) { resetEnv := unsetEnv(t) defer resetEnv() - os.Setenv("KUBE_CONFIG_PATHS", "test-fixtures/kube-config.yaml") + os.Setenv("KUBE_CONFIG_PATH", "test-fixtures/kube-config.yaml") os.Setenv("KUBE_CTX", "gcp") rc := terraform.NewResourceConfigRaw(map[string]interface{}{}) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index e9687eead0..b45c37b1f0 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -15,9 +15,7 @@ Use the navigation to the left to read about the available resources. ```hcl provider "kubernetes" { - config_paths = [ - "~/.kube/config" - ] + config_path = "~/.kube/config" config_context = "my-context" } @@ -124,6 +122,7 @@ The following arguments are supported: * `client_certificate` - (Optional) PEM-encoded client certificate for TLS authentication. Can be sourced from `KUBE_CLIENT_CERT_DATA`. * `client_key` - (Optional) PEM-encoded client certificate key for TLS authentication. Can be sourced from `KUBE_CLIENT_KEY_DATA`. * `cluster_ca_certificate` - (Optional) PEM-encoded root certificates bundle for TLS authentication. Can be sourced from `KUBE_CLUSTER_CA_CERT_DATA`. +* `config_path` - (Optional) A path to a kube config files. Can be sourced from `KUBE_CONFIG_PATH`. * `config_paths` - (Optional) A list of paths to the kube config files. Can be sourced from `KUBE_CONFIG_PATHS`, which allows `:` to be used to delimit multiple paths. * `config_context` - (Optional) Context to choose from the config file. Can be sourced from `KUBE_CTX`. * `config_context_auth_info` - (Optional) Authentication info context of the kube config (name of the kubeconfig user, `--user` flag in `kubectl`). Can be sourced from `KUBE_CTX_AUTH_INFO`.