Skip to content

Commit

Permalink
Add options to use kubectl on custom path and ability to use token au…
Browse files Browse the repository at this point in the history
…thentication
  • Loading branch information
cmosh authored and bonifaido committed Jan 16, 2020
1 parent c84b714 commit 7bb8793
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8
github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A=
github.com/hashicorp/terraform-plugin-sdk v1.4.0 h1:b1LluARpES0Gq78oF4a9of3eS0iXM5JTwlt604vGvBY=
github.com/hashicorp/terraform-plugin-sdk v1.4.0/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg=
github.com/hashicorp/terraform-plugin-sdk v1.5.0 h1:hzac/oigJkGup0kI+PwBGI4/fvG7Na8kM8j9xCBrmWo=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg=
github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
Expand Down
25 changes: 24 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type config struct {
kubeconfig string
kubeconfigContent string
kubeconfigContext string
kubectlPath string
kubectlToken string
}

func main() {
Expand All @@ -39,6 +41,14 @@ func main() {
Type: schema.TypeString,
Optional: true,
},
"kubectl_path": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"kubectl_token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
ResourcesMap: map[string]*schema.Resource{
"k8s_manifest": resourceManifest(),
Expand All @@ -48,6 +58,8 @@ func main() {
kubeconfig: d.Get("kubeconfig").(string),
kubeconfigContent: d.Get("kubeconfig_content").(string),
kubeconfigContext: d.Get("kubeconfig_context").(string),
kubectlPath: d.Get("kubectl_path").(string),
kubectlToken: d.Get("kubectl_token").(string),
}, nil
},
}
Expand Down Expand Up @@ -133,11 +145,22 @@ func kubectl(m interface{}, kubeconfig string, args ...string) *exec.Cmd {
}

context := m.(*config).kubeconfigContext
path := m.(*config).kubectlPath
token := m.(*config).kubectlToken

if path == "" {
path = "kubectl"
}

if context != "" {
args = append([]string{"--context", context}, args...)
}

return exec.Command("kubectl", args...)
if token != "" {
args = append([]string{"--token", token}, args...)
}

return exec.Command(path, args...)
}

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

0 comments on commit 7bb8793

Please sign in to comment.