github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/team_collaborator.go (about)

     1  // Copyright 2019 The Terraformer Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package heroku
    16  
    17  import (
    18  	"context"
    19  	"log"
    20  
    21  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    22  	heroku "github.com/heroku/heroku-go/v5"
    23  )
    24  
    25  type TeamCollaboratorGenerator struct {
    26  	HerokuService
    27  }
    28  
    29  func (g TeamCollaboratorGenerator) createResources(svc *heroku.Service, teamList []heroku.Team) []terraformutils.Resource {
    30  	var resources []terraformutils.Resource
    31  	for _, team := range teamList {
    32  		apps, err := svc.TeamAppListByTeam(context.TODO(), team.ID, &heroku.ListRange{Field: "id"})
    33  		if err != nil {
    34  			log.Println(err)
    35  		}
    36  		for _, app := range apps {
    37  			collaborators, err := svc.TeamAppCollaboratorList(context.TODO(), app.ID, &heroku.ListRange{Field: "id"})
    38  			if err != nil {
    39  				log.Println(err)
    40  			}
    41  			for _, collaborator := range collaborators {
    42  				resources = append(resources, terraformutils.NewResource(
    43  					collaborator.ID,
    44  					collaborator.ID,
    45  					"heroku_team_collaborator",
    46  					"heroku",
    47  					map[string]string{"app": app.Name},
    48  					[]string{},
    49  					map[string]interface{}{}))
    50  			}
    51  		}
    52  	}
    53  	return resources
    54  }
    55  
    56  func (g *TeamCollaboratorGenerator) InitResources() error {
    57  	svc := g.generateService()
    58  	output, err := svc.TeamList(context.TODO(), &heroku.ListRange{Field: "id"})
    59  	if err != nil {
    60  		return err
    61  	}
    62  	g.Resources = g.createResources(svc, output)
    63  	return nil
    64  }