Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added vault proto option #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package provider
import (
"context"
"fmt"
"log"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/vault/api"
"k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"log"
"os"
"strings"
)

const (
Expand All @@ -22,6 +23,7 @@ const (
resInit = provider + "_init"
argVaultUrl = "vault_url"
argVaultAddr = "vault_addr"
argVaulProtocol = "vault_proto"
argVaultSkipVerify = "vault_skip_verify"
argRequestHeaders = "request_headers"
argKubeConfig = "kube_config"
Expand Down Expand Up @@ -98,6 +100,12 @@ func providerSchema() map[string]*schema.Schema {
Optional: true,
Description: "Vault instance URL",
},
argVaulProtocol: {
Type: schema.TypeString,
Optional: true,
Description: "Protocol with which vault will be accessed",
Default: "http",
},
argVaultSkipVerify: {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -180,6 +188,9 @@ func providerSchema() map[string]*schema.Schema {

func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
if d.Get(argVaulProtocol).(string) != "http" && d.Get(argVaulProtocol).(string) != "https" {
return nil, diag.Errorf("The only available vault protocols are http and https")
}
a := &apiClient{}
loader := &clientcmd.ClientConfigLoadingRules{}
overrides := &clientcmd.ConfigOverrides{}
Expand Down Expand Up @@ -245,7 +256,7 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
return nil, diag.FromErr(fmt.Errorf("failed to configure: %s", err))
}

a.url = fmt.Sprintf("http://localhost:%s", a.kubeConn.localPort)
a.url = fmt.Sprintf("%s://localhost:%s", d.Get(argVaulProtocol).(string), a.kubeConn.localPort)
} else {
if u := d.Get(argVaultAddr).(string); u != "" {
a.url = u
Expand Down
Loading