From 96d9549bef95b541f2291722d344b1342b4f2f84 Mon Sep 17 00:00:00 2001 From: Zulhilmi Zainudin Date: Mon, 1 Nov 2021 12:26:24 +0800 Subject: [PATCH] Add support to use non-production API server URL --- civo/provider.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/civo/provider.go b/civo/provider.go index a2f6c644..bb0566b7 100644 --- a/civo/provider.go +++ b/civo/provider.go @@ -2,6 +2,8 @@ package civo import ( "fmt" + "log" + "os" "github.com/civo/civogo" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -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 }