Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy_url configuration #179

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.dll
*.exe
.DS_Store
.vscode
example.tf
terraform.tfplan
terraform.tfstate
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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.
Expand Down
24 changes: 17 additions & 7 deletions kubernetes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"bytes"
"context"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mitchellh/go-homedir"
Expand All @@ -19,13 +27,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
aggregator "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
"log"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
)

func Provider() *schema.Provider {
Expand Down Expand Up @@ -120,6 +121,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,
Expand Down Expand Up @@ -373,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()
Expand Down