github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azuredevops/group.go (about)

     1  package azuredevpos
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/microsoft/azure-devops-go-api/azuredevops/graph"
     7  )
     8  
     9  type GroupGenerator struct {
    10  	AzureDevOpsService
    11  }
    12  
    13  func (az *GroupGenerator) listResources() ([]graph.GraphGroup, error) {
    14  
    15  	client, fail := az.getGraphClient()
    16  	if fail != nil {
    17  		return nil, fail
    18  	}
    19  	ctx := context.Background()
    20  	var resources []graph.GraphGroup
    21  	pageArgs := graph.ListGroupsArgs{}
    22  	pages, err := client.ListGroups(ctx, pageArgs)
    23  	for ; err == nil; pages, err = client.ListGroups(ctx, pageArgs) {
    24  		resources = append(resources, *pages.GraphGroups...)
    25  		if pages.ContinuationToken == nil {
    26  			return resources, nil
    27  		}
    28  		pageArgs = graph.ListGroupsArgs{
    29  			ContinuationToken: &(*pages.ContinuationToken)[0],
    30  		}
    31  	}
    32  	return nil, err
    33  }
    34  
    35  func (az *GroupGenerator) appendResource(resource *graph.GraphGroup) {
    36  
    37  	resourceName := firstNonEmpty(resource.DisplayName, resource.MailAddress, resource.OriginId)
    38  	az.appendSimpleResource(*resource.Descriptor, *resourceName, "azuredevops_group")
    39  }
    40  
    41  func (az *GroupGenerator) InitResources() error {
    42  
    43  	resources, err := az.listResources()
    44  	if err != nil {
    45  		return err
    46  	}
    47  	for _, resource := range resources {
    48  		az.appendResource(&resource)
    49  	}
    50  	return nil
    51  }
    52  
    53  func (az *GroupGenerator) GetResourceConnections() map[string][]string {
    54  
    55  	return map[string][]string{
    56  		"project": {"scope", "id"},
    57  	}
    58  }