github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/app_feature.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 AppFeatureGenerator struct { 27 HerokuService 28 } 29 30 func (g AppFeatureGenerator) createResources(svc *heroku.Service, appList []heroku.App) []terraformutils.Resource { 31 var resources []terraformutils.Resource 32 for _, app := range appList { 33 output, err := svc.AppFeatureList(context.TODO(), app.ID, &heroku.ListRange{Field: "id"}) 34 if err != nil { 35 log.Println(err) 36 } 37 for _, appFeature := range output { 38 resources = append(resources, terraformutils.NewSimpleResource( 39 fmt.Sprintf("%s:%s", app.Name, appFeature.ID), 40 appFeature.Name, 41 "heroku_app_feature", 42 "heroku", 43 []string{})) 44 } 45 } 46 return resources 47 } 48 49 func (g *AppFeatureGenerator) InitResources() error { 50 svc := g.generateService() 51 output, err := svc.AppList(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 }