diff --git a/kubernetes/provider.go b/kubernetes/provider.go index 6ae08a37c1..a6ba33880c 100644 --- a/kubernetes/provider.go +++ b/kubernetes/provider.go @@ -101,6 +101,14 @@ func Provider() *schema.Provider { Description: "Path to the kube config file. Can be set with KUBE_CONFIG_PATH.", ConflictsWith: []string{"config_paths"}, }, + "config_data": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + DefaultFunc: schema.EnvDefaultFunc("KUBE_CONFIG_DATA", nil), + Description: "Raw Kubernetes config data. Can be set with KUBE_CONFIG_DATA. Takes precidence over all over configutaion. No overrides allowed.", + ConflictsWith: []string{"config_path", "config_paths"}, + }, "config_context": { Type: schema.TypeString, Optional: true, @@ -496,8 +504,23 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer return m, diag.Diagnostics{} } -func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, diag.Diagnostics) { - diags := make(diag.Diagnostics, 0) +func initializeConfiguration(d *schema.ResourceData) (*restclient.Config, error) { + + configData, configDataOk := d.GetOk("config_data") + if configDataOk { + cc, err := clientcmd.NewClientConfigFromBytes([]byte(configData.(string))) + if err != nil { + log.Printf("[ERROR] Invalid config_data was provided. Provider operations likely to fail: %v", err) + return nil, nil + } + cfg, err := cc.ClientConfig() + if err != nil { + log.Printf("[ERROR] Invalid config_data was provided. Provider operations likely to fail: %v", err) + return nil, nil + } + return cfg, nil + } + overrides := &clientcmd.ConfigOverrides{} loader := &clientcmd.ClientConfigLoadingRules{} diff --git a/manifest/provider/provider_config.go b/manifest/provider/provider_config.go index 2adfb1cc63..7676424a12 100644 --- a/manifest/provider/provider_config.go +++ b/manifest/provider/provider_config.go @@ -123,6 +123,17 @@ func GetProviderConfigSchema() *tfprotov5.Schema { DescriptionKind: 0, Deprecated: false, }, + { + Name: "config_data", + Type: tftypes.String, + Description: "Raw Kubernetes config data. Can be set with KUBE_CONFIG_DATA. Takes precidence over all over configutaion. No overrides allowed.", + Required: false, + Optional: true, + Computed: false, + Sensitive: true, + DescriptionKind: 0, + Deprecated: false, + }, { Name: "config_context", Type: tftypes.String,