Skip to content

Commit

Permalink
Remove empty credentials check (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston authored Jan 15, 2021
1 parent c99a737 commit c38916e
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions helm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"log"
"os"
"strings"
"sync"

Expand Down Expand Up @@ -225,52 +224,6 @@ func kubernetesResource() *schema.Resource {
}
}

var apiTokenMountPath = "/var/run/secrets/kubernetes.io/serviceaccount"

func inCluster() bool {
host, port := os.Getenv("KUBERNETES_SERVICE_HOST"), os.Getenv("KUBERNETES_SERVICE_PORT")
if host == "" || port == "" {
return false
}

if _, err := os.Stat(apiTokenMountPath); err != nil {
return false
}
return true
}

var authDocumentationURL = "https://registry.terraform.io/providers/hashicorp/helm/latest/docs#authentication"

func checkKubernetesConfigurationValid(d *schema.ResourceData) error {
if inCluster() {
log.Printf("[DEBUG] Terraform appears to be running inside the Kubernetes cluster")
return nil
}

if os.Getenv("KUBE_CONFIG_PATHS") != "" {
return nil
}

atLeastOneOf := []string{
"host",
"config_path",
"config_paths",
"client_certificate",
"token",
"exec",
}
for _, a := range atLeastOneOf {
if _, ok := k8sGetOk(d, a); ok {
return nil
}
}

return fmt.Errorf(`provider not configured: you must configure a path to your kubeconfig
or explicitly supply credentials via the provider block or environment variables.
See our authentication documentation at: %s`, authDocumentationURL)
}

func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, diag.Diagnostics) {
m := &Meta{data: d}

Expand Down Expand Up @@ -356,10 +309,6 @@ func (m *Meta) GetHelmConfiguration(namespace string) (*action.Configuration, er
debug("[INFO] GetHelmConfiguration start")
actionConfig := new(action.Configuration)

if err := checkKubernetesConfigurationValid(m.data); err != nil {
return nil, err
}

kc, err := newKubeConfig(m.data, &namespace)
if err != nil {
return nil, err
Expand Down

0 comments on commit c38916e

Please sign in to comment.