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

feat: add optional metal_base (EQUINIX_API_METAL_BASE) provider config #338

Closed
wants to merge 1 commit into from
Closed
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
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
5 changes: 3 additions & 2 deletions equinix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var (
// provider.
type Config struct {
BaseURL string
MetalBasePath string
AuthToken string
ClientID string
ClientSecret string
Expand Down Expand Up @@ -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
Expand All @@ -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{
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
Loading