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