Skip to content

Commit

Permalink
Add support to use non-production API server URL (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
zulh-civo committed Nov 8, 2021
1 parent 08d2fbb commit b654130
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion civo/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package civo

import (
"fmt"
"log"
"os"

"github.com/civo/civogo"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -77,10 +79,24 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return nil, fmt.Errorf("[ERR] token not found")
}

client, err := civogo.NewClient(tokenValue, regionValue)
var client *civogo.Client
var err error

apiURL, envExists := os.LookupEnv("CIVO_API_URL")
if envExists && apiURL != "" {
client, err = civogo.NewClientWithURL(tokenValue, apiURL, regionValue)
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Civo API URL: %s\n", apiURL)
return client, nil
}

client, err = civogo.NewClient(tokenValue, regionValue)
if err != nil {
return nil, err
}
log.Printf("[DEBUG] Civo API URL: %s\n", "https://api.civo.com")
return client, nil

}

0 comments on commit b654130

Please sign in to comment.