Skip to content

Commit

Permalink
Merge pull request #990 from hashicorp/consistent-api-version
Browse files Browse the repository at this point in the history
Explicitly set the API version instead of relying on SDK default version
  • Loading branch information
manicminer authored Jan 27, 2023
2 parents 58136a1 + 7a2bb6f commit 69d2760
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions internal/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/auth"
"github.com/manicminer/hamilton/environments"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

type ClientBuilder struct {
Expand Down Expand Up @@ -53,6 +53,7 @@ func (b *ClientBuilder) Build(ctx context.Context) (*Client, error) {

o := &common.ClientOptions{
Authorizer: authorizer,
ApiVersion: msgraph.Version10,
Environment: client.Environment,
TenantID: client.TenantID,

Expand Down
7 changes: 5 additions & 2 deletions internal/common/client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
"github.com/hashicorp/terraform-provider-azuread/version"
"github.com/manicminer/hamilton/auth"
"github.com/manicminer/hamilton/environments"
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/version"
)

type contextKey string
Expand All @@ -28,6 +27,7 @@ type ClientOptions struct {
TerraformVersion string

Authorizer auth.Authorizer
ApiVersion msgraph.ApiVersion
}

func (o ClientOptions) ConfigureClient(c *msgraph.Client) {
Expand All @@ -46,6 +46,9 @@ func (o ClientOptions) ConfigureClient(c *msgraph.Client) {

// Default retry limit, can be overridden from within a resource
c.RetryableClient.RetryMax = 9

// Explicitly set API version
c.ApiVersion = o.ApiVersion
}

func (o ClientOptions) requestLogger(req *http.Request) (*http.Request, error) {
Expand Down
3 changes: 1 addition & 2 deletions internal/services/applications/client/client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package client

import (
"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/environments"
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
)

type Client struct {
Expand Down
4 changes: 1 addition & 3 deletions internal/services/conditionalaccess/client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package client

import (
"github.com/manicminer/hamilton/msgraph"

"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

type Client struct {
Expand All @@ -17,7 +16,6 @@ func NewClient(o *common.ClientOptions) *Client {

policiesClient := msgraph.NewConditionalAccessPoliciesClient(o.TenantID)
o.ConfigureClient(&policiesClient.BaseClient)
policiesClient.BaseClient.ApiVersion = msgraph.Version10

return &Client{
NamedLocationsClient: namedLocationsClient,
Expand Down
1 change: 0 additions & 1 deletion internal/services/serviceprincipals/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func NewClient(o *common.ClientOptions) *Client {
o.ConfigureClient(&directoryObjectsClient.BaseClient)

servicePrincipalsClient := msgraph.NewServicePrincipalsClient(o.TenantID)
servicePrincipalsClient.BaseClient.ApiVersion = msgraph.Version10
o.ConfigureClient(&servicePrincipalsClient.BaseClient)

synchronizationJobClient := msgraph.NewSynchronizationJobClient(o.TenantID)
Expand Down

0 comments on commit 69d2760

Please sign in to comment.