Skip to content

Commit

Permalink
Added a error handler to the provider in the case of the token not wa…
Browse files Browse the repository at this point in the history
…s found

Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed May 31, 2020
1 parent 4dfc12d commit a456dad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions civo/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package civo

import (
"fmt"
"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
Expand Down Expand Up @@ -51,7 +52,10 @@ func Provider() terraform.ResourceProvider {

// Provider configuration
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
token := d.Get("token").(string)
client, _ := civogo.NewClient(token)
return client, nil
if token, ok := d.GetOk("token"); ok {
client, _ := civogo.NewClient(token.(string))
return client, nil
} else {
return nil, fmt.Errorf("[ERR] token not found")
}
}

0 comments on commit a456dad

Please sign in to comment.