Commit a65875b0 authored by Yann KAISER's avatar Yann KAISER

Updated provider (no need to put endpoint in provider infos in TF files, it...

Updated provider (no need to put endpoint in provider infos in TF files, it now reads a config.json file at the root of the TF projet)
parent 7bf6b39c
package one
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
......@@ -18,7 +19,7 @@ func Provider() *schema.Provider {
Schema: map[string]*schema.Schema{
"endpoint": {
Type: schema.TypeString,
Required: true,
Optional: true,
Description: "Endpoint",
},
......@@ -71,9 +72,27 @@ func Provider() *schema.Provider {
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
// Setup configuration
var endpoint = ""
var username = ""
var passwd = ""
var configJSON map[string]interface{}
bytes, err := ioutil.ReadFile("./config.json")
if err == nil {
if err = json.Unmarshal(bytes, &configJSON); err != nil {
return nil, fmt.Errorf("error while reading the config.json file")
}
}
endp, okEndpoint := d.GetOk("endpoint")
if okEndpoint {
endpoint = endp.(string)
} else {
endpoint = configJSON["endpoint"].(string)
}
usern, okUsername := d.GetOk("username")
if okUsername {
username = usern.(string)
......@@ -103,7 +122,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
vmTimeout = v.(int)
}
config := CreateConfig(d.Get("endpoint").(string), username, passwd, oneflowHost, vmTimeout)
config := CreateConfig(endpoint, username, passwd, oneflowHost, vmTimeout)
// Return new client
return config.Client()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment