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

SDK Migration 09: migrate groups to go-azure-sdk #1483

Merged
merged 1 commit into from
Sep 24, 2024
Merged
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
84 changes: 66 additions & 18 deletions internal/services/groups/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,83 @@
package client

import (
administrativeunitmemberBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/directory/beta/administrativeunitmember"
"github.com/hashicorp/go-azure-sdk/microsoft-graph/directoryobjects/stable/directoryobject"
groupBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/groups/beta/group"
memberBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/groups/beta/member"
memberofBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/groups/beta/memberof"
ownerBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/groups/beta/owner"
transitivememberBeta "github.com/hashicorp/go-azure-sdk/microsoft-graph/groups/beta/transitivemember"
"github.com/hashicorp/terraform-provider-azuread/internal/common"
"github.com/manicminer/hamilton/msgraph"
)

// Note: Whilst it is technically possible that we could use both the Stable and Beta APIs for groups (retaining use of
// Beta APIs solely for those properties that require it), we are currently using the Beta APIs pretty much across the
// board owing to the complexity of the azuread_group resource, and known bugs when retrieving members with the Stable API.

type Client struct {
AdministrativeUnitsClient *msgraph.AdministrativeUnitsClient
DirectoryObjectsClient *msgraph.DirectoryObjectsClient
GroupsClient *msgraph.GroupsClient
AdministrativeUnitMemberClientBeta *administrativeunitmemberBeta.AdministrativeUnitMemberClient
DirectoryObjectClient *directoryobject.DirectoryObjectClient
GroupClientBeta *groupBeta.GroupClient
GroupMemberClientBeta *memberBeta.MemberClient
GroupMemberOfClientBeta *memberofBeta.MemberOfClient
GroupOwnerClientBeta *ownerBeta.OwnerClient
GroupTransitiveMemberClientBeta *transitivememberBeta.TransitiveMemberClient
}

func NewClient(o *common.ClientOptions) *Client {
administrativeUnitsClient := msgraph.NewAdministrativeUnitsClient()
o.ConfigureClient(&administrativeUnitsClient.BaseClient)
func NewClient(o *common.ClientOptions) (*Client, error) {
administrativeUnitMemberClientBeta, err := administrativeunitmemberBeta.NewAdministrativeUnitMemberClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(administrativeUnitMemberClientBeta.Client)

directoryObjectClient, err := directoryobject.NewDirectoryObjectClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(directoryObjectClient.Client)

// resourceBehaviorOptions & resourceProvisioningOptions fields not supported in v1.0 API
groupClientBeta, err := groupBeta.NewGroupClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(groupClientBeta.Client)

// SDK uses wrong endpoint for v1.0 API, see https://github.com/manicminer/hamilton/issues/222
administrativeUnitsClient.BaseClient.ApiVersion = msgraph.VersionBeta
// Group members not returned in full when using v1.0 API, see https://github.com/hashicorp/terraform-provider-azuread/issues/1018
memberClientBeta, err := memberBeta.NewMemberClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(memberClientBeta.Client)

directoryObjectsClient := msgraph.NewDirectoryObjectsClient()
o.ConfigureClient(&directoryObjectsClient.BaseClient)
memberOfClientBeta, err := memberofBeta.NewMemberOfClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(memberOfClientBeta.Client)

groupsClient := msgraph.NewGroupsClient()
o.ConfigureClient(&groupsClient.BaseClient)
ownerClientBeta, err := ownerBeta.NewOwnerClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(ownerClientBeta.Client)

// Group members not returned in full when using v1.0 API, see https://github.com/hashicorp/terraform-provider-azuread/issues/1018
groupsClient.BaseClient.ApiVersion = msgraph.VersionBeta
transitiveMemberClientBeta, err := transitivememberBeta.NewTransitiveMemberClientWithBaseURI(o.Environment.MicrosoftGraph)
if err != nil {
return nil, err
}
o.Configure(transitiveMemberClientBeta.Client)

return &Client{
AdministrativeUnitsClient: administrativeUnitsClient,
DirectoryObjectsClient: directoryObjectsClient,
GroupsClient: groupsClient,
}
AdministrativeUnitMemberClientBeta: administrativeUnitMemberClientBeta,
DirectoryObjectClient: directoryObjectClient,
GroupClientBeta: groupClientBeta,
GroupMemberClientBeta: memberClientBeta,
GroupMemberOfClientBeta: memberOfClientBeta,
GroupOwnerClientBeta: ownerClientBeta,
GroupTransitiveMemberClientBeta: transitiveMemberClientBeta,
}, nil
}
79 changes: 79 additions & 0 deletions internal/services/groups/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package groups

const (
groupResourceName = "azuread_group"
groupDuplicateValueError = "Request contains a property with duplicate values"
)

const (
GroupTypeDynamicMembership = "DynamicMembership"
GroupTypeUnified = "Unified"
)

var possibleValuesForGroupType = []string{GroupTypeDynamicMembership, GroupTypeUnified}

const (
GroupResourceBehaviorOptionAllowOnlyMembersToPost = "AllowOnlyMembersToPost"
GroupResourceBehaviorOptionCalendarMemberReadOnly = "CalendarMemberReadOnly"
GroupResourceBehaviorOptionConnectorsDisabled = "ConnectorsDisabled"
GroupResourceBehaviorOptionHideGroupInOutlook = "HideGroupInOutlook"
GroupResourceBehaviorOptionSkipExchangeInstantOn = "SkipExchangeInstantOn"
GroupResourceBehaviorOptionSubscribeMembersToCalendarEventsDisabled = "SubscribeMembersToCalendarEventsDisabled"
GroupResourceBehaviorOptionSubscribeNewGroupMembers = "SubscribeNewGroupMembers"
GroupResourceBehaviorOptionWelcomeEmailDisabled = "WelcomeEmailDisabled"
)

var possibleValuesForGroupResourceBehaviorOptions = []string{
GroupResourceBehaviorOptionAllowOnlyMembersToPost,
GroupResourceBehaviorOptionCalendarMemberReadOnly,
GroupResourceBehaviorOptionConnectorsDisabled,
GroupResourceBehaviorOptionHideGroupInOutlook,
GroupResourceBehaviorOptionSkipExchangeInstantOn,
GroupResourceBehaviorOptionSubscribeMembersToCalendarEventsDisabled,
GroupResourceBehaviorOptionSubscribeNewGroupMembers,
GroupResourceBehaviorOptionWelcomeEmailDisabled,
}

const (
GroupResourceProvisioningOptionTeam = "Team"
)

var possibleValuesForGroupResourceProvisioningOptions = []string{GroupResourceProvisioningOptionTeam}

const (
GroupThemeNone = ""
GroupThemeBlue = "Blue"
GroupThemeGreen = "Green"
GroupThemeOrange = "Orange"
GroupThemePink = "Pink"
GroupThemePurple = "Purple"
GroupThemeRed = "Red"
GroupThemeTeal = "Teal"
)

var possibleValuesForGroupTheme = []string{
GroupThemeNone,
GroupThemeBlue,
GroupThemeGreen,
GroupThemeOrange,
GroupThemePink,
GroupThemePurple,
GroupThemeRed,
GroupThemeTeal,
}

const (
GroupVisibilityHiddenMembership = "Hiddenmembership"
GroupVisibilityPrivate = "Private"
GroupVisibilityPublic = "Public"
)

var possibleValuesForGroupVisibility = []string{GroupVisibilityHiddenMembership, GroupVisibilityPrivate, GroupVisibilityPublic}

const (
OnPremisesGroupTypeUniversalDistributionGroup = "UniversalDistributionGroup"
OnPremisesGroupTypeUniversalMailEnabledSecurityGroup = "UniversalMailEnabledSecurityGroup"
OnPremisesGroupTypeUniversalSecurityGroup = "UniversalSecurityGroup"
)

var possibleValuesForOnPremisesGroupType = []string{OnPremisesGroupTypeUniversalDistributionGroup, OnPremisesGroupTypeUniversalMailEnabledSecurityGroup, OnPremisesGroupTypeUniversalSecurityGroup}
Loading
Loading