Skip to content

Commit

Permalink
Merge pull request #283 from equinix/fix-credentials-login-failure
Browse files Browse the repository at this point in the history
configure tokensource only if client id/secret are set
  • Loading branch information
ocobles authored Dec 2, 2022
2 parents f989c30 + 86e6e86 commit f000c35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.11.1 (2 Dec, 2022)

BUG FIXES:

- An error loading provider configuration, introduced in v1.11.0, was preventing using the provider without Fabric credentials [#283](https://github.com/equinix/terraform-provider-equinix/pull/283)

## 1.11.0 (1 Dec, 2022)

FEATURES:
Expand Down
29 changes: 15 additions & 14 deletions equinix/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ of a service without the required credentials will return an API error referring
'Invalid authentication token' or 'error when acquiring token'.
More information on the provider configuration can be found here:
https://registry.terraform.io/providers/equinix/equinix/latest/docs
Original Error:`
https://registry.terraform.io/providers/equinix/equinix/latest/docs`
)

var (
Expand Down Expand Up @@ -122,18 +120,22 @@ func (c *Config) Load(ctx context.Context) error {
BaseURL: c.BaseURL,
}
authClient = authConfig.New(ctx)
tke, err := authConfig.TokenSource(ctx, authClient).Token()
if err != nil {

if c.ClientID != "" && c.ClientSecret != "" {
tke, err := authConfig.TokenSource(ctx, authClient).Token()
if err != nil {
return err
if err != nil {
return err
}
}
if tke != nil {
c.FabricAuthToken = tke.AccessToken
}
}
if tke != nil {
c.FabricAuthToken = tke.AccessToken
}
if c.FabricAuthToken == "" {
c.FabricAuthToken = c.Token
}
}

if c.FabricAuthToken == "" {
c.FabricAuthToken = c.Token
}
authClient.Timeout = c.requestTimeout()
authClient.Transport = logging.NewTransport("Equinix", authClient.Transport)
Expand Down Expand Up @@ -163,8 +165,7 @@ func (c *Config) Load(ctx context.Context) error {
// NewFabricClient returns a new client for accessing Equinix Fabric's v4 API.
func (c *Config) NewFabricClient() *v4.APIClient {
transport := logging.NewTransport("Equinix Fabric", http.DefaultTransport)
var authClient *http.Client
authClient = &http.Client{
authClient := &http.Client{
Transport: transport,
}
authClient.Timeout = c.requestTimeout()
Expand Down

0 comments on commit f000c35

Please sign in to comment.