Skip to content

Commit

Permalink
Revisit provider configuration
Browse files Browse the repository at this point in the history
Allow setting the api endpoint through an environment variable. This
also allows us to properly set the endpoint to a non-prod environment
for the acceptance tests.

Also, fix the double-implemented default value!

Signed-off-by: Dimitrios Karagiannis <[email protected]>
  • Loading branch information
alkar committed Nov 6, 2019
1 parent 6c908d6 commit 91a6227
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions megaport/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func Provider() terraform.ResourceProvider {
"api_endpoint": {
Type: schema.TypeString,
Optional: true,
Default: api.EndpointProduction,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"MEGAPORT_API_ENDPOINT",
}, api.EndpointProduction),
},
},

Expand All @@ -47,12 +49,8 @@ func Provider() terraform.ResourceProvider {
},

ConfigureFunc: func(d *schema.ResourceData) (interface{}, error) {
endpoint := api.EndpointProduction
if e, ok := d.GetOk("api_endpoint"); ok {
endpoint = e.(string)
}
client := api.NewClient(endpoint)
log.Printf("initialised megaport api client at %s", endpoint)
client := api.NewClient(d.Get("api_endpoint").(string))
fmt.Printf("initialised megaport api client at %s\n", client.BaseURL)
if v, ok := d.GetOk("token"); ok { // TODO: is it an error if not found?
client.Token = v.(string)
}
Expand Down

0 comments on commit 91a6227

Please sign in to comment.