github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/heroku/heroku_provider.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 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type HerokuProvider struct { //nolint 25 terraformutils.Provider 26 email string 27 apiKey string 28 } 29 30 func (p *HerokuProvider) Init(args []string) error { 31 if os.Getenv("HEROKU_EMAIL") == "" { 32 return errors.New("set HEROKU_EMAIL env var") 33 } 34 p.email = os.Getenv("HEROKU_EMAIL") 35 36 if os.Getenv("HEROKU_API_KEY") == "" { 37 return errors.New("set HEROKU_API_KEY env var") 38 } 39 p.apiKey = os.Getenv("HEROKU_API_KEY") 40 41 return nil 42 } 43 44 func (p *HerokuProvider) GetName() string { 45 return "heroku" 46 } 47 48 func (p *HerokuProvider) GetProviderData(arg ...string) map[string]interface{} { 49 return map[string]interface{}{ 50 "provider": map[string]interface{}{ 51 "heroku": map[string]interface{}{ 52 "email": p.email, 53 }, 54 }, 55 } 56 } 57 58 func (HerokuProvider) GetResourceConnections() map[string]map[string][]string { 59 return map[string]map[string][]string{} 60 } 61 62 func (p *HerokuProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 63 return map[string]terraformutils.ServiceGenerator{ 64 "account_feature": &AccountFeatureGenerator{}, 65 "addon": &AddOnGenerator{}, 66 "addon_attachment": &AddOnAttachmentGenerator{}, 67 "app": &AppGenerator{}, 68 "app_config_association": &AppConfigAssociationGenerator{}, 69 "app_feature": &AppFeatureGenerator{}, 70 "app_webhook": &AppWebhookGenerator{}, 71 "build": &BuildGenerator{}, 72 "cert": &CertGenerator{}, 73 "domain": &DomainGenerator{}, 74 "drain": &DrainGenerator{}, 75 "formation": &FormationGenerator{}, 76 "pipeline": &PipelineGenerator{}, 77 "pipeline_coupling": &PipelineCouplingGenerator{}, 78 "team_collaborator": &TeamCollaboratorGenerator{}, 79 "team_member": &TeamMemberGenerator{}, 80 } 81 } 82 83 func (p *HerokuProvider) InitService(serviceName string, verbose bool) error { 84 var isSupported bool 85 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 86 return errors.New("heroku: " + serviceName + " not supported service") 87 } 88 p.Service = p.GetSupportedService()[serviceName] 89 p.Service.SetName(serviceName) 90 p.Service.SetVerbose(verbose) 91 p.Service.SetProviderName(p.GetName()) 92 p.Service.SetArgs(map[string]interface{}{ 93 "email": p.email, 94 "api_key": p.apiKey, 95 }) 96 return nil 97 }