Skip to content

Commit bc45567

Browse files
committed
Change config_path -> config_paths
1 parent 3be7d12 commit bc45567

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

kubernetes/provider.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"log"
88
"net/http"
9+
"os"
10+
"strings"
911

1012
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1113

@@ -68,11 +70,11 @@ func Provider() *schema.Provider {
6870
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLUSTER_CA_CERT_DATA", ""),
6971
Description: "PEM-encoded root certificates bundle for TLS authentication.",
7072
},
71-
"config_path": {
72-
Type: schema.TypeString,
73+
"config_paths": {
74+
Type: schema.TypeList,
75+
Elem: &schema.Schema{Type: schema.TypeString},
7376
Optional: true,
74-
DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", ""),
75-
Description: "Path to the kube config file. Can be set with KUBE_CONFIG_PATH environment variable.",
77+
Description: "A list of paths to kube config file. Can be set with KUBE_CONFIG_PATHS environment variable.",
7678
},
7779
"config_context": {
7880
Type: schema.TypeString,
@@ -260,13 +262,26 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error)
260262
overrides := &clientcmd.ConfigOverrides{}
261263
loader := &clientcmd.ClientConfigLoadingRules{}
262264

263-
if configPath, ok := d.GetOk("config_path"); ok && configPath.(string) != "" {
264-
path, err := homedir.Expand(configPath.(string))
265-
if err != nil {
266-
return nil, err
265+
configPaths := []string{}
266+
if v, ok := d.Get("config_paths").([]string); ok && len(v) > 0 {
267+
configPaths = v
268+
} else if v := os.Getenv("KUBE_CONFIG_PATHS"); v != "" {
269+
// NOTE we have to do this here because the schema
270+
// does not yet allow you to set a default for a TypeList
271+
configPaths = strings.Split(v, ":")
272+
}
273+
274+
if len(configPaths) > 0 {
275+
expandedPaths := []string{}
276+
for _, p := range configPaths {
277+
path, err := homedir.Expand(p)
278+
if err != nil {
279+
return nil, err
280+
}
281+
log.Printf("[DEBUG] Using kubeconfig: %s", path)
282+
expandedPaths = append(expandedPaths, path)
267283
}
268-
log.Printf("[DEBUG] Configuration file is: %s", path)
269-
loader.ExplicitPath = path
284+
loader.Precedence = expandedPaths
270285

271286
ctxSuffix := "; default context"
272287

website/docs/index.html.markdown

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Use the navigation to the left to read about the available resources.
1515

1616
```hcl
1717
provider "kubernetes" {
18-
config_path = "~/.kube/config"
18+
config_paths = [
19+
"~/.kube/config"
20+
]
1921
config_context = "my-context"
2022
}
2123
@@ -79,12 +81,6 @@ the provider will try to use the service account token from the `/var/run/secret
7981
Detection of in-cluster execution is based on the sole availability both of the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables,
8082
with non empty values.
8183

82-
```hcl
83-
provider "kubernetes" {
84-
load_config_file = "false"
85-
}
86-
```
87-
8884
If you have any other static configuration setting specified in a config file or static configuration, in-cluster service account token will not be tried.
8985

9086
### Statically defined credentials
@@ -93,8 +89,6 @@ Another way is **statically** define TLS certificate credentials:
9389

9490
```hcl
9591
provider "kubernetes" {
96-
load_config_file = "false"
97-
9892
host = "https://104.196.242.174"
9993
10094
client_certificate = "${file("~/.kube/client-cert.pem")}"
@@ -107,8 +101,6 @@ or username and password (HTTP Basic Authorization):
107101

108102
```hcl
109103
provider "kubernetes" {
110-
load_config_file = "false"
111-
112104
host = "https://104.196.242.174"
113105
114106
username = "username"
@@ -132,7 +124,7 @@ The following arguments are supported:
132124
* `client_certificate` - (Optional) PEM-encoded client certificate for TLS authentication. Can be sourced from `KUBE_CLIENT_CERT_DATA`.
133125
* `client_key` - (Optional) PEM-encoded client certificate key for TLS authentication. Can be sourced from `KUBE_CLIENT_KEY_DATA`.
134126
* `cluster_ca_certificate` - (Optional) PEM-encoded root certificates bundle for TLS authentication. Can be sourced from `KUBE_CLUSTER_CA_CERT_DATA`.
135-
* `config_path` - (Optional) Path to the kube config file. Can be sourced from `KUBE_CONFIG`.
127+
* `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.
136128
* `config_context` - (Optional) Context to choose from the config file. Can be sourced from `KUBE_CTX`.
137129
* `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`.
138130
* `config_context_cluster` - (Optional) Cluster context of the kube config (name of the kubeconfig cluster, `--cluster` flag in `kubectl`). Can be sourced from `KUBE_CTX_CLUSTER`.

0 commit comments

Comments
 (0)