Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: add configuration option to use a specific hostname or base path #1270

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hostname and base path for the API client
```
19 changes: 18 additions & 1 deletion cloudflare/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_ACCOUNT_ID", nil),
Description: "Configure API client to always use that account",
},

"api_hostname": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_API_HOSTNAME", "api.cloudflare.com"),
Description: "Configure the hostname used by the API client",
},

"api_base_path": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CLOUDFLARE_API_BASE_PATH", "/client/v4"),
Description: "Configure the base path used by the API client",
},
},

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

func providerConfigure(d *schema.ResourceData, terraformVersion string) (interface{}, error) {
baseURL := cloudflare.BaseURL(
"https://" + d.Get("api_hostname").(string) + d.Get("api_base_path").(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
2 changes: 2 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ 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.
* `api_hostname` - (Optional) Configure the API client to use a specific hostname. Default: "api.cloudflare.com"
* `api_base_path` - (Optional) Configure the API client to use a specific base path. Default: "/client/v4"