From ff1e3bb4f56176fb04b9363faf3b81939227e9b7 Mon Sep 17 00:00:00 2001 From: Anshit-Agrawal <51432327+Anshit-Agrawal@users.noreply.github.com> Date: Wed, 23 Apr 2025 00:37:54 +0530 Subject: [PATCH] Adding the support to override the defaul the observability api url In one of our example, instead of using api..signalfx.com we are making use of external-api..signalfx.com api URL. So in order to achieve it, following support is added in which if apiUrl is passed in providers.tf, it wil take precedence otherwise default one will be used --- synthetics/provider.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/synthetics/provider.go b/synthetics/provider.go index 6e4645d..4483911 100644 --- a/synthetics/provider.go +++ b/synthetics/provider.go @@ -17,6 +17,7 @@ package synthetics import ( "context" "regexp" + "strings" sc2 "github.com/splunk/syntheticsclient/v2/syntheticsclientv2" @@ -48,6 +49,12 @@ func Provider() *schema.Provider { Description: "Splunk Observability Realm (E.G. `us1`). Will pull from `REALM` environment variable if available. For Rigor use realm rigor", DefaultFunc: schema.EnvDefaultFunc("REALM", nil), }, + "apiUrl": { + Type: schema.TypeString, + Optional: true, + Description: "Splunk Observability Realm API Endpoint (E.G. `https://api..signalfx.com`). Will pull from `API_URL` environment variable if available.", + DefaultFunc: schema.EnvDefaultFunc("API_URL", nil), + }, }, ResourcesMap: map[string]*schema.Resource{ "synthetics_create_http_check": resourceHttpCheck(), @@ -82,14 +89,26 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{} token := d.Get("apikey").(string) realm := d.Get("realm").(string) product := d.Get("product").(string) + apiUrl := d.Get("apiUrl").(string) var diags diag.Diagnostics if product == "observability" { if token != "" && realm != "" { - c := sc2.NewClient(token, realm) - - return c, diags + if apiUrl != "" { + args := sc2.ClientArgs { + timeoutSeconds: 30, + publicBaseUrl: strings.TrimSuffix(apiUrl, "/") + "/v2/synthetics" + } + + c := sc2.NewConfigurableClient(token, realm, args) + + return c, diags + } else { + c := sc2.NewClient(token, realm) + + return c, diags + } } c := sc2.NewClient(token, realm)