github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/pagerduty/user.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 pagerduty 16 17 import ( 18 "fmt" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 pagerduty "github.com/heimweh/go-pagerduty/pagerduty" 22 ) 23 24 type UserGenerator struct { 25 PagerDutyService 26 } 27 28 func (g *UserGenerator) createUserResources(client *pagerduty.Client) error { 29 var offset = 0 30 options := pagerduty.ListUsersOptions{} 31 for { 32 options.Offset = offset 33 resp, _, err := client.Users.List(&options) 34 if err != nil { 35 return err 36 } 37 38 for _, user := range resp.Users { 39 g.Resources = append(g.Resources, terraformutils.NewSimpleResource( 40 user.ID, 41 fmt.Sprintf("user_%s", user.ID), 42 "pagerduty_user", 43 g.ProviderName, 44 []string{}, 45 )) 46 } 47 48 if !resp.More { 49 break 50 } 51 52 offset += resp.Limit 53 } 54 55 return nil 56 } 57 58 func (g *UserGenerator) InitResources() error { 59 client, err := g.Client() 60 if err != nil { 61 return err 62 } 63 64 funcs := []func(*pagerduty.Client) error{ 65 g.createUserResources, 66 } 67 68 for _, f := range funcs { 69 err := f(client) 70 if err != nil { 71 return err 72 } 73 } 74 75 return nil 76 }