Skip to content

Commit

Permalink
Change config_path -> config_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston committed Nov 13, 2020
1 parent 3be7d12 commit bc45567
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
35 changes: 25 additions & 10 deletions kubernetes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"log"
"net/http"
"os"
"strings"

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

Expand Down Expand Up @@ -68,11 +70,11 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("KUBE_CLUSTER_CA_CERT_DATA", ""),
Description: "PEM-encoded root certificates bundle for TLS authentication.",
},
"config_path": {
Type: schema.TypeString,
"config_paths": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_PATH", ""),
Description: "Path to the kube config file. Can be set with KUBE_CONFIG_PATH environment variable.",
Description: "A list of paths to kube config file. Can be set with KUBE_CONFIG_PATHS environment variable.",
},
"config_context": {
Type: schema.TypeString,
Expand Down Expand Up @@ -260,13 +262,26 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error)
overrides := &clientcmd.ConfigOverrides{}
loader := &clientcmd.ClientConfigLoadingRules{}

if configPath, ok := d.GetOk("config_path"); ok && configPath.(string) != "" {
path, err := homedir.Expand(configPath.(string))
if err != nil {
return nil, err
configPaths := []string{}
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
// does not yet allow you to set a default for a TypeList
configPaths = strings.Split(v, ":")
}

if len(configPaths) > 0 {
expandedPaths := []string{}
for _, p := range configPaths {
path, err := homedir.Expand(p)
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Using kubeconfig: %s", path)
expandedPaths = append(expandedPaths, path)
}
log.Printf("[DEBUG] Configuration file is: %s", path)
loader.ExplicitPath = path
loader.Precedence = expandedPaths

ctxSuffix := "; default context"

Expand Down
16 changes: 4 additions & 12 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Use the navigation to the left to read about the available resources.

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

```hcl
provider "kubernetes" {
load_config_file = "false"
}
```

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.

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

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

```hcl
provider "kubernetes" {
load_config_file = "false"
host = "https://104.196.242.174"
username = "username"
Expand All @@ -132,7 +124,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) Path to the kube config file. Can be sourced from `KUBE_CONFIG`.
* `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`.
* `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`.
Expand Down

0 comments on commit bc45567

Please sign in to comment.