Skip to content

Commit

Permalink
feat: add optional metal_base (EQUINIX_API_METAL_BASE) provider config
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Jun 2, 2023
1 parent b23f9ea commit 097e452
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion equinix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var (
// provider.
type Config struct {
BaseURL string
MetalBasePath string
AuthToken string
ClientID string
ClientSecret string
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions equinix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 097e452

Please sign in to comment.