github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/team_member.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 "fmt" 20 "log" 21 22 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 23 heroku "github.com/heroku/heroku-go/v5" 24 ) 25 26 type TeamMemberGenerator struct { 27 HerokuService 28 } 29 30 func (g TeamMemberGenerator) createResources(svc *heroku.Service, teamList []heroku.Team) []terraformutils.Resource { 31 var resources []terraformutils.Resource 32 for _, team := range teamList { 33 output, err := svc.TeamMemberList(context.TODO(), team.ID, &heroku.ListRange{Field: "id"}) 34 if err != nil { 35 log.Println(err) 36 } 37 for _, member := range output { 38 resources = append(resources, terraformutils.NewSimpleResource( 39 fmt.Sprintf("%s:%s", team.ID, member.Email), 40 member.ID, 41 "heroku_team_member", 42 "heroku", 43 []string{})) 44 } 45 } 46 return resources 47 } 48 49 func (g *TeamMemberGenerator) InitResources() error { 50 svc := g.generateService() 51 output, err := svc.TeamList(context.TODO(), &heroku.ListRange{Field: "id"}) 52 if err != nil { 53 return err 54 } 55 g.Resources = g.createResources(svc, output) 56 return nil 57 }