File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,12 +4,12 @@ import (
44 "fmt"
55 "io/ioutil"
66 "log"
7- "os"
87 "strings"
98
109 "github.com/hashicorp/terraform/helper/schema"
1110 "github.com/hashicorp/terraform/terraform"
1211 "github.com/hashicorp/vault/api"
12+ "github.com/mitchellh/go-homedir"
1313)
1414
1515func Provider () terraform.ResourceProvider {
@@ -127,13 +127,16 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
127127 token := d .Get ("token" ).(string )
128128 if token == "" {
129129 // Use the vault CLI's token, if present.
130- tokenFile := fmt .Sprintf ("%s/.vault-token" , os .Getenv ("HOME" ))
131- tokenBytes , err := ioutil .ReadFile (tokenFile )
130+ homePath , err := homedir .Dir ()
131+ if err != nil {
132+ return nil , fmt .Errorf ("No vault token found: %s" , err )
133+ }
134+ tokenBytes , err := ioutil .ReadFile (homePath + "/.vault-token" )
132135 if err != nil {
133136 return nil , fmt .Errorf ("No vault token found: %s" , err )
134137 }
135138
136- token = string (tokenBytes )
139+ token = strings . TrimSpace ( string (tokenBytes ) )
137140 }
138141
139142 // In order to enforce our relatively-short lease TTL, we derive a
You can’t perform that action at this time.
0 commit comments