Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

kubectl_path added to provider for custom kubectl path #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ The provider takes optional configuration to specify a `kubeconfig` file:
```hcl
provider "k8s" {
kubeconfig = "/path/to/kubeconfig"

# Optional, Default: "kubectl" (`kubectl` in PATH)
kubectl_path = "/path/to/kubectl"
}
```

Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

type config struct {
kubeconfig string
kubectl_path string
}

func main() {
Expand All @@ -25,13 +26,19 @@ func main() {
Type: schema.TypeString,
Optional: true,
},
"kubectl_path": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "kubectl",
},
},
ResourcesMap: map[string]*schema.Resource{
"k8s_manifest": resourceManifest(),
},
ConfigureFunc: func(d *schema.ResourceData) (interface{}, error) {
return &config{
kubeconfig: d.Get("kubeconfig").(string),
kubeconfig: d.Get("kubeconfig").(string),
kubectl_path: d.Get("kubectl_path").(string),
}, nil
},
}
Expand Down Expand Up @@ -71,10 +78,11 @@ func run(cmd *exec.Cmd) error {

func kubectl(m interface{}, args ...string) *exec.Cmd {
kubeconfig := m.(*config).kubeconfig
kubectl_path := m.(*config).kubectl_path
if kubeconfig != "" {
args = append([]string{"--kubeconfig", kubeconfig}, args...)
}
return exec.Command("kubectl", args...)
return exec.Command(kubectl_path, args...)
}

func resourceManifestCreate(d *schema.ResourceData, m interface{}) error {
Expand Down