Skip to content

Commit

Permalink
Adds KUBECONFIG field for using existing .kube/config
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Jan 12, 2021
1 parent 470f171 commit 97d611e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/terraform/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ import (
"github.com/kubernetes-sigs/aws-iam-authenticator/pkg/token"
"github.com/pkg/errors"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

// Func which configures the Kubernetes provider.
// https://github.com/terraform-providers/terraform-provider-kubernetes/blob/master/kubernetes/provider.go
func Func(d *schema.ResourceData) (interface{}, error) {
if v, ok := d.GetOk(FieldKubeConfig); ok {
cfg, err := clientcmd.BuildConfigFromFlags("", v.(string))
if err != nil {
return nil, err
}

return NewForConfig(cfg)
}

cfg := &rest.Config{}

// Overriding with static configuration
Expand Down
8 changes: 8 additions & 0 deletions internal/terraform/config/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import "github.com/hashicorp/terraform/helper/schema"

const (
// FieldKubeConfig defines the path to the Kubernetes config file.
FieldKubeConfig = "kubeconfig"
// FieldHost identifier for host field.
FieldHost = "host"
// FieldInsecure identifier for insecure field.
Expand All @@ -20,6 +22,12 @@ const (
// Fields which are used to configure the Kubernetes client.
func Fields() map[string]*schema.Schema {
return map[string]*schema.Schema{
FieldKubeConfig: {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("KUBECONFIG", ""),
Description: "The path to the Kubernetes config file.",
},
FieldHost: {
Type: schema.TypeString,
Optional: true,
Expand Down

0 comments on commit 97d611e

Please sign in to comment.