diff --git a/docs/index.md b/docs/index.md index 77c7f2997..f74ceee60 100644 --- a/docs/index.md +++ b/docs/index.md @@ -112,6 +112,10 @@ services, and `auth_token` to interact with Equinix Metal. * `max_retry_wait_seconds` (Optional) Maximum time to wait in case of network failure. +* `metal_base` (Optional) The Equinix Metal API base path for the API `endpoint`. + This argument can also be specified with the `EQUINIX_API_METAL_BASE` shell environment + variable. (Defaults to `/metal/v1`) + These parameters can be provided in [Terraform variable files](https://www.terraform.io/docs/configuration/variables.html#variable-definitions-tfvars-files) or as environment variables. Nevertheless, please note that it is [not diff --git a/equinix/config.go b/equinix/config.go index 56e55c55f..c2a4c3053 100644 --- a/equinix/config.go +++ b/equinix/config.go @@ -71,6 +71,7 @@ var ( // provider. type Config struct { BaseURL string + MetalBasePath string AuthToken string ClientID string ClientSecret string @@ -196,7 +197,7 @@ func (c *Config) NewMetalClient() *packngo.Client { retryClient.CheckRetry = MetalRetryPolicy standardClient := retryClient.StandardClient() baseURL, _ := url.Parse(c.BaseURL) - baseURL.Path = path.Join(baseURL.Path, metalBasePath) + "/" + baseURL.Path = path.Join(baseURL.Path, c.MetalBasePath) + "/" client, _ := packngo.NewClientWithBaseURL(consumerToken, c.AuthToken, standardClient, baseURL.String()) client.UserAgent = c.fullUserAgent(client.UserAgent) c.metalUserAgent = client.UserAgent diff --git a/equinix/provider.go b/equinix/provider.go index c6100044f..0606ee0ce 100644 --- a/equinix/provider.go +++ b/equinix/provider.go @@ -27,6 +27,7 @@ var ( const ( endpointEnvVar = "EQUINIX_API_ENDPOINT" + metalBaseEnvVar = "EQUINIX_API_METAL_BASE" clientIDEnvVar = "EQUINIX_API_CLIENTID" clientSecretEnvVar = "EQUINIX_API_CLIENTSECRET" clientTokenEnvVar = "EQUINIX_API_TOKEN" @@ -54,6 +55,12 @@ func Provider() *schema.Provider { ValidateFunc: validation.IsURLWithHTTPorHTTPS, Description: fmt.Sprintf("The Equinix API base URL to point out desired environment. Defaults to %s", DefaultBaseURL), }, + "metal_base": { + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc(metalBaseEnvVar, metalBasePath), + Description: fmt.Sprintf("The Equinix Metal API base path for the API `endpoint`. Defaults to %s", metalBasePath), + }, "client_id": { Type: schema.TypeString, Optional: true,