Skip to content

Commit

Permalink
Merge pull request #980 from favoretti/favoretti/storage_keys
Browse files Browse the repository at this point in the history
Add `id` attribute to `azuredevops_groups` datasource
  • Loading branch information
xuzhang3 committed Feb 28, 2024
2 parents a1c2e25 + 5765680 commit 6f6ac2a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions azuredevops/internal/service/graph/data_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/graph"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/client"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/converter"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils/tfhelper"
)

Expand All @@ -28,6 +29,10 @@ func DataGroups() *schema.Resource {
Set: getGroupHash,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"descriptor": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -111,6 +116,18 @@ func dataSourceGroupsRead(d *schema.ResourceData, m interface{}) error {
return fmt.Errorf("Error flatten groups. Error: %w", err)
}

for _, group := range fgroups {
grp := group.(map[string]interface{})

storageKey, err := clients.GraphClient.GetStorageKey(clients.Ctx, graph.GetStorageKeyArgs{
SubjectDescriptor: converter.String(grp["descriptor"].(string)),
})
if err != nil {
return err
}
grp["id"] = storageKey.Value.String()
}

d.SetId("groups-" + uuid.New().String())
d.Set("groups", fgroups)
return nil
Expand Down
14 changes: 13 additions & 1 deletion azuredevops/internal/service/graph/data_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func TestGroupsDataSource_HandlesContinuationToken(t *testing.T) {
firstListGroupCallArgs := graph.ListGroupsArgs{ScopeDescriptor: projectDescriptor}
continuationToken := "continuation-token"
firstListGroupCallResponse := createPaginatedResponse(continuationToken, groupMeta{name: "name1", descriptor: "descriptor1", origin: "vsts", originId: originID.String()})

var calls []*gomock.Call

firstCall := graphClient.
EXPECT().
ListGroups(clients.Ctx, firstListGroupCallArgs).
Expand All @@ -129,7 +132,16 @@ func TestGroupsDataSource_HandlesContinuationToken(t *testing.T) {
ListGroups(clients.Ctx, secondListGroupCallArgs).
Return(secondListGroupCallResponse, nil)

gomock.InOrder(firstCall, secondCall)
calls = append(calls, firstCall, secondCall)
calls = append(calls, graphClient.
EXPECT().
GetStorageKey(clients.Ctx, gomock.Any()).
Return(&graph.GraphStorageKeyResult{
Links: "",
Value: &id,
}, nil).Times(2))

gomock.InOrder(calls...)

err := dataSourceGroupsRead(resourceData, clients)
require.Nil(t, err)
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The following attributes are exported:

- `groups` - A set of existing groups in your Azure DevOps Organization or project with details about every single group which includes:

- `id` - The group ID.
- `description` - A short phrase to help human readers disambiguate groups with similar names
- `descriptor` - The descriptor is the primary way to reference the graph subject while the system is running. This field will uniquely identify the same graph subject across both Accounts and Organizations.
- `display_name` - This is the non-unique display name of the graph subject. To change this field, you must alter its value in the source provider.
Expand Down

0 comments on commit 6f6ac2a

Please sign in to comment.