github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/pagerduty/pagerduty_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 pagerduty 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/zclconf/go-cty/cty" 23 ) 24 25 type PagerDutyProvider struct { //nolint 26 terraformutils.Provider 27 token string 28 } 29 30 func (p *PagerDutyProvider) Init(args []string) error { 31 if token := os.Getenv("PAGERDUTY_TOKEN"); token != "" { 32 p.token = os.Getenv("PAGERDUTY_TOKEN") 33 } 34 if len(args) > 0 && args[0] != "" { 35 p.token = args[0] 36 } 37 return nil 38 } 39 40 func (p *PagerDutyProvider) GetName() string { 41 return "pagerduty" 42 } 43 44 func (p *PagerDutyProvider) GetConfig() cty.Value { 45 return cty.ObjectVal(map[string]cty.Value{ 46 "token": cty.StringVal(p.token), 47 }) 48 } 49 50 func (p *PagerDutyProvider) GetProviderData(arg ...string) map[string]interface{} { 51 return map[string]interface{}{ 52 "provider": map[string]interface{}{ 53 "pagerduty": map[string]interface{}{ 54 "token": p.token, 55 }, 56 }, 57 } 58 } 59 60 func (PagerDutyProvider) GetResourceConnections() map[string]map[string][]string { 61 return map[string]map[string][]string{} 62 } 63 64 func (p *PagerDutyProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 65 return map[string]terraformutils.ServiceGenerator{ 66 "business_service": &BusinessServiceGenerator{}, 67 "escalation_policy": &EscalationPolicyGenerator{}, 68 "ruleset": &RulesetGenerator{}, 69 "schedule": &ScheduleGenerator{}, 70 "service": &ServiceGenerator{}, 71 "team": &TeamGenerator{}, 72 "user": &UserGenerator{}, 73 } 74 } 75 76 func (p *PagerDutyProvider) InitService(serviceName string, verbose bool) error { 77 var isSupported bool 78 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 79 return errors.New(p.GetName() + ": " + serviceName + " not supported service") 80 } 81 p.Service = p.GetSupportedService()[serviceName] 82 p.Service.SetName(serviceName) 83 p.Service.SetVerbose(verbose) 84 p.Service.SetProviderName(p.GetName()) 85 p.Service.SetArgs(map[string]interface{}{ 86 "token": p.token, 87 }) 88 return nil 89 }