github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/domain.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 DomainGenerator struct { 26 HerokuService 27 } 28 29 func (g DomainGenerator) createResources(svc *heroku.Service, appList []heroku.App) []terraformutils.Resource { 30 var resources []terraformutils.Resource 31 for _, app := range appList { 32 output, err := svc.DomainList(context.TODO(), app.ID, &heroku.ListRange{Field: "id"}) 33 if err != nil { 34 log.Println(err) 35 } 36 for _, domain := range output { 37 resources = append(resources, terraformutils.NewResource( 38 domain.ID, 39 domain.ID, 40 "heroku_domain", 41 "heroku", 42 map[string]string{"app": app.Name}, 43 []string{}, 44 map[string]interface{}{})) 45 } 46 } 47 return resources 48 } 49 50 func (g *DomainGenerator) InitResources() error { 51 svc := g.generateService() 52 output, err := svc.AppList(context.TODO(), &heroku.ListRange{Field: "id"}) 53 if err != nil { 54 return err 55 } 56 g.Resources = g.createResources(svc, output) 57 return nil 58 }