Data source DataTeams in  azuredevops/internal/service/core/data_teams.go is now able to load all (accessible) teams from all (accessible) projects
@@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
+ "github.com/ahmetb/go-linq"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform/helper/hashcode"
@@ -18,7 +19,7 @@ func DataTeams() *schema.Resource {
Schema: map[string]*schema.Schema{
"project_id": {
Type: schema.TypeString,
- Required: true,
+ Optional: true,
ValidateFunc: validation.IsUUID,
},
"teams": {
@@ -73,8 +74,26 @@ func hashTeam(v interface{}) int {
func dataTeamsRead(d *schema.ResourceData, m interface{}) error {
clients := m.(*client.AggregatedClient)
- projectID := d.Get("project_id").(string)
+ var projectIDList []string
+ data, ok := d.GetOk("project_id")
+ if ok {
+ projectIDList = []string{
+ data.(string),
+ }
+ } else {
+ projectList, err := getProjectsForStateAndName(clients, string(core.ProjectStateValues.All), "")
+ if err != nil {
+ return err
+ }
+ linq.From(projectList).
+ Select(func(e interface{}) interface{} {
+ return e.(core.TeamProjectReference).Id.String()
+ }).
+ ToSlice(&projectIDList)
+ }
+ result := make([]interface{}, 0)
+ for _, projectID := range projectIDList {
teamList, err := clients.CoreClient.GetTeams(clients.Ctx, core.GetTeamsArgs{
ProjectId: converter.String(projectID),
Mine: converter.Bool(false),
@@ -86,7 +105,7 @@ func dataTeamsRead(d *schema.ResourceData, m interface{}) error {
}
if teamList == nil || len(*teamList) <= 0 {
- return nil
+ continue
}
teams := make([]interface{}, len(*teamList))
@@ -124,10 +143,12 @@ func dataTeamsRead(d *schema.ResourceData, m interface{}) error {
teams[i] = s
}
+ result = append(result, teams...)
+ }
// The ID for this resource is meaningless so we can just assign a random ID
d.SetId(fmt.Sprintf("%d", rand.Int()))
- if err := d.Set("teams", teams); err != nil {
+ if err := d.Set("teams", result); err != nil {
return fmt.Errorf("Error setting `teams`: %+v", err)
}
