Skip to content

Commit 940af6a

Browse files
committed
Support config_path and config_paths
1 parent 5a16a65 commit 940af6a

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

kubernetes/provider.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ func Provider() *schema.Provider {
7676
Optional: true,
7777
Description: "A list of paths to kube config files. Can be set with KUBE_CONFIG_PATHS environment variable.",
7878
},
79+
"config_path": {
80+
Type: schema.TypeString,
81+
Optional: true,
82+
DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", ""),
83+
Description: "Path to the kube config file, defaults to ~/.kube/config",
84+
},
7985
"config_context": {
8086
Type: schema.TypeString,
8187
Optional: true,
@@ -263,7 +269,10 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error)
263269
loader := &clientcmd.ClientConfigLoadingRules{}
264270

265271
configPaths := []string{}
266-
if v, ok := d.Get("config_paths").([]string); ok && len(v) > 0 {
272+
273+
if v, ok := d.Get("config_path").(string); ok && v != "" {
274+
configPaths = []string{v}
275+
} else if v, ok := d.Get("config_paths").([]string); ok && len(v) > 0 {
267276
configPaths = v
268277
} else if v := os.Getenv("KUBE_CONFIG_PATHS"); v != "" {
269278
// NOTE we have to do this here because the schema
@@ -281,7 +290,12 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error)
281290
log.Printf("[DEBUG] Using kubeconfig: %s", path)
282291
expandedPaths = append(expandedPaths, path)
283292
}
284-
loader.Precedence = expandedPaths
293+
294+
if len(expandedPaths) == 1 {
295+
loader.ExplicitPath = expandedPaths[0]
296+
} else {
297+
loader.Precedence = expandedPaths
298+
}
285299

286300
ctxSuffix := "; default context"
287301

kubernetes/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestProvider_configure(t *testing.T) {
7373
resetEnv := unsetEnv(t)
7474
defer resetEnv()
7575

76-
os.Setenv("KUBE_CONFIG_PATHS", "test-fixtures/kube-config.yaml")
76+
os.Setenv("KUBE_CONFIG_PATH", "test-fixtures/kube-config.yaml")
7777
os.Setenv("KUBE_CTX", "gcp")
7878

7979
rc := terraform.NewResourceConfigRaw(map[string]interface{}{})

website/docs/index.html.markdown

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

1616
```hcl
1717
provider "kubernetes" {
18-
config_paths = [
19-
"~/.kube/config"
20-
]
18+
config_path = "~/.kube/config"
2119
config_context = "my-context"
2220
}
2321
@@ -124,6 +122,7 @@ The following arguments are supported:
124122
* `client_certificate` - (Optional) PEM-encoded client certificate for TLS authentication. Can be sourced from `KUBE_CLIENT_CERT_DATA`.
125123
* `client_key` - (Optional) PEM-encoded client certificate key for TLS authentication. Can be sourced from `KUBE_CLIENT_KEY_DATA`.
126124
* `cluster_ca_certificate` - (Optional) PEM-encoded root certificates bundle for TLS authentication. Can be sourced from `KUBE_CLUSTER_CA_CERT_DATA`.
125+
* `config_path` - (Optional) A path to a kube config files. Can be sourced from `KUBE_CONFIG_PATH`.
127126
* `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.
128127
* `config_context` - (Optional) Context to choose from the config file. Can be sourced from `KUBE_CTX`.
129128
* `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`.

0 commit comments

Comments
 (0)