From 9c07d389ca8e6db462f9704d88a759f4e2b2172d Mon Sep 17 00:00:00 2001 From: Alexander Chernov Date: Wed, 6 Dec 2023 20:24:26 +0000 Subject: [PATCH] Added `proxy_url` config. See https://github.com/alekc/terraform-provider-kubectl/issues/75 --- docs/index.md | 1 + kubernetes/provider.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/docs/index.md b/docs/index.md index bc492044..fefd6058 100755 --- a/docs/index.md +++ b/docs/index.md @@ -69,6 +69,7 @@ The following arguments are supported: * `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`. * `token` - (Optional) Token of your service account. Can be sourced from `KUBE_TOKEN`. +* `proxy_url` - (Optional) URL to the proxy to be used for all API requests. URLs with "http", "https", and "socks5" schemes are supported. Can be sourced from `KUBE_PROXY_URL`. * `exec` - (Optional) Configuration block to use an [exec-based credential plugin] (https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins), e.g. call an external command to receive user credentials. * `api_version` - (Required) API version to use when decoding the ExecCredentials resource, e.g. `client.authentication.k8s.io/v1beta1`. * `command` - (Required) Command to execute. diff --git a/kubernetes/provider.go b/kubernetes/provider.go index 945335ad..8fd0e7f1 100644 --- a/kubernetes/provider.go +++ b/kubernetes/provider.go @@ -120,6 +120,12 @@ func Provider() *schema.Provider { DefaultFunc: schema.EnvDefaultFunc("KUBE_TOKEN", ""), Description: "Token to authentifcate an service account", }, + "proxy_url": { + Type: schema.TypeString, + Optional: true, + Description: "URL to the proxy to be used for all API requests", + DefaultFunc: schema.EnvDefaultFunc("KUBE_PROXY_URL", ""), + }, "load_config_file": { Type: schema.TypeBool, Optional: true, @@ -374,6 +380,9 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error) if v, ok := d.GetOk("token"); ok { overrides.AuthInfo.Token = v.(string) } + if v, ok := d.GetOk("proxy_url"); ok { + overrides.ClusterDefaults.ProxyURL = v.(string) + } cc := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, overrides) cfg, err := cc.ClientConfig()