Skip to content

Commit

Permalink
provider: add configuration option to use a specific base_url
Browse files Browse the repository at this point in the history
Following on from cloudflare/cloudflare-go#606, this allows the provider
to pass through the ability to override the base URL that the API client
uses for calls.
  • Loading branch information
jacobbednarz committed Oct 20, 2021
1 parent 73a37ae commit 8db7762
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/1270.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
provider: add the ability to configure a different base URL for the API client
```
10 changes: 9 additions & 1 deletion cloudflare/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_ACCOUNT_ID", nil),
Description: "Configure API client to always use that account",
},

"base_url": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_BASE_URL", "https://api.cloudflare.com/client/v4"),
Description: "Configure the base URL used by the API client",
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -183,9 +190,10 @@ func Provider() *schema.Provider {
}

func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
baseURL := cloudflare.BaseURL(d.Get("base_url").(string))
limitOpt := cloudflare.UsingRateLimit(float64(d.Get("rps").(int)))
retryOpt := cloudflare.UsingRetryPolicy(d.Get("retries").(int), d.Get("min_backoff").(int), d.Get("max_backoff").(int))
options := []cloudflare.Option{limitOpt, retryOpt}
options := []cloudflare.Option{limitOpt, retryOpt, baseURL}

if d.Get("api_client_logging").(bool) {
options = append(options, cloudflare.UsingLogger(log.New(os.Stderr, "", log.LstdFlags)))
Expand Down
1 change: 1 addition & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ The following arguments are supported:
* `account_id` - (Optional) Configure API client with this account ID, so calls use the account API rather than the (default) user API.
This is required for other users in your account to have access to the resources you manage.
This can also be specified with the `CLOUDFLARE_ACCOUNT_ID` shell environment variable.
* `base_url` - (Optional) Configure the API client to use a specific base URL. Default: "https://api.cloudflare.com"

0 comments on commit 8db7762

Please sign in to comment.