Skip to content

Commit 1748337

Browse files
Add proxy_url attribute to provider configuration block (#1441)
Co-authored-by: John Houston <[email protected]> Co-authored-by: Peter Hrvola <[email protected]>
1 parent 0a493f2 commit 1748337

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

kubernetes/provider.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func Provider() *schema.Provider {
107107
DefaultFunc: schema.EnvDefaultFunc("KUBE_TOKEN", ""),
108108
Description: "Token to authenticate an service account",
109109
},
110+
"proxy_url": {
111+
Type: schema.TypeString,
112+
Optional: true,
113+
Description: "URL to the proxy to be used for all API requests",
114+
DefaultFunc: schema.EnvDefaultFunc("KUBE_PROXY_URL", ""),
115+
},
110116
"exec": {
111117
Type: schema.TypeList,
112118
Optional: true,
@@ -410,6 +416,10 @@ func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error)
410416
overrides.AuthInfo.Exec = exec
411417
}
412418

419+
if v, ok := d.GetOk("proxy_url"); ok {
420+
overrides.ClusterDefaults.ProxyURL = v.(string)
421+
}
422+
413423
cc := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, overrides)
414424
cfg, err := cc.ClientConfig()
415425
if err != nil {

manifest/provider/configure.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,24 @@ func (s *RawProviderServer) ConfigureProvider(ctx context.Context, req *tfprotov
486486
overrides.AuthInfo.Token = token
487487
}
488488

489+
var proxyURL string
490+
if !providerConfig["proxy_url"].IsNull() && providerConfig["proxy_url"].IsKnown() {
491+
err = providerConfig["proxy_url"].As(&proxyURL)
492+
if err != nil {
493+
// invalid attribute type - this shouldn't happen, bail out for now
494+
response.Diagnostics = append(response.Diagnostics, &tfprotov5.Diagnostic{
495+
Severity: tfprotov5.DiagnosticSeverityError,
496+
Summary: "Provider configuration: failed to assert type of 'proxy_url' value",
497+
Detail: err.Error(),
498+
})
499+
return response, nil
500+
}
501+
overrides.ClusterDefaults.ProxyURL = proxyURL
502+
}
503+
if proxyUrl, ok := os.LookupEnv("KUBE_PROXY_URL"); ok && proxyUrl != "" {
504+
overrides.ClusterDefaults.ProxyURL = proxyURL
505+
}
506+
489507
if !providerConfig["exec"].IsNull() && providerConfig["exec"].IsKnown() {
490508
var execBlock []tftypes.Value
491509
err = providerConfig["exec"].As(&execBlock)

manifest/provider/provider_config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ func GetProviderConfigSchema() *tfprotov5.Schema {
153153
DescriptionKind: 0,
154154
Deprecated: false,
155155
},
156+
{
157+
Name: "proxy_url",
158+
Type: tftypes.String,
159+
Description: "URL to the proxy to be used for all API requests",
160+
Required: false,
161+
Optional: true,
162+
Computed: false,
163+
Sensitive: false,
164+
DescriptionKind: 0,
165+
Deprecated: false,
166+
},
156167
},
157168
BlockTypes: []*tfprotov5.SchemaNestedBlock{
158169
{

website/docs/index.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ The following arguments are supported:
148148
* `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`.
149149
* `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`.
150150
* `token` - (Optional) Token of your service account. Can be sourced from `KUBE_TOKEN`.
151+
* `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`.
151152
* `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.
152153
* `api_version` - (Required) API version to use when decoding the ExecCredentials resource, e.g. `client.authentication.k8s.io/v1beta1`.
153154
* `command` - (Required) Command to execute.

0 commit comments

Comments
 (0)