Add an override for the DigitalOcean API URL
This allows you to change the default URL for accessing the DigitalOcean API. It's similar to what you would do when overriding an endpoint in the AWS provider, only with the DO API it's an all or nothing change.
This commit is contained in:
parent
ff9b300baf
commit
afa7377d63
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -20,9 +21,10 @@ import (
|
|||
)
|
||||
|
||||
type Config struct {
|
||||
Token string
|
||||
AccessID string
|
||||
SecretKey string
|
||||
Token string
|
||||
APIEndpoint string
|
||||
AccessID string
|
||||
SecretKey string
|
||||
}
|
||||
|
||||
type CombinedConfig struct {
|
||||
|
@ -65,6 +67,12 @@ func (c *Config) Client() (*CombinedConfig, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
apiURL, err := url.Parse(c.APIEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.BaseURL = apiURL
|
||||
|
||||
if logging.IsDebugOrHigher() {
|
||||
do.OnRequestCompleted(logRequestAndResponse)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ func Provider() terraform.ResourceProvider {
|
|||
DefaultFunc: schema.EnvDefaultFunc("DIGITALOCEAN_TOKEN", nil),
|
||||
Description: "The token key for API operations.",
|
||||
},
|
||||
"api_endpoint": {
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("DIGITALOCEAN_API_URL", "https://api.digitalocean.com"),
|
||||
Description: "The URL to use for the DigitalOcean API.",
|
||||
},
|
||||
"spaces_access_id": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
|
@ -71,9 +77,10 @@ func Provider() terraform.ResourceProvider {
|
|||
|
||||
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
||||
config := Config{
|
||||
Token: d.Get("token").(string),
|
||||
AccessID: d.Get("spaces_access_id").(string),
|
||||
SecretKey: d.Get("spaces_secret_key").(string),
|
||||
Token: d.Get("token").(string),
|
||||
APIEndpoint: d.Get("api_endpoint").(string),
|
||||
AccessID: d.Get("spaces_access_id").(string),
|
||||
SecretKey: d.Get("spaces_secret_key").(string),
|
||||
}
|
||||
|
||||
return config.Client()
|
||||
|
|
Loading…
Reference in New Issue