From 2f82bb84a00839670ec3ab54bbe05ef6c2a1012c Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Fri, 2 Jun 2023 18:18:45 -0400 Subject: [PATCH] feat: add optional metal_base (EQUINIX_API_METAL_BASE) provider config Signed-off-by: Marques Johansson --- docs/index.md | 4 ++++ equinix/config.go | 5 +++-- equinix/provider.go | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) 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 085100e80..7a8e22e97 100644 --- a/equinix/config.go +++ b/equinix/config.go @@ -72,6 +72,7 @@ var ( // provider. type Config struct { BaseURL string + MetalBasePath string AuthToken string ClientID string ClientSecret string @@ -200,7 +201,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 @@ -220,7 +221,7 @@ func (c *Config) NewMetalGoClient() *metalv1.APIClient { standardClient := retryClient.StandardClient() baseURL, _ := url.Parse(c.BaseURL) - baseURL.Path = path.Join(baseURL.Path, metalBasePath) + "/" + baseURL.Path = path.Join(baseURL.Path, c.MetalBasePath) + "/" configuration := metalv1.NewConfiguration() configuration.Servers = metalv1.ServerConfigurations{ diff --git a/equinix/provider.go b/equinix/provider.go index d8eda438f..3112b2294 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,