github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/ns1/ns1_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 ns1 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type Ns1Provider struct { //nolint 25 terraformutils.Provider 26 apiKey string 27 } 28 29 func (p *Ns1Provider) Init(args []string) error { 30 if os.Getenv("NS1_APIKEY") == "" { 31 return errors.New("set NS1_APIKEY env var") 32 } 33 p.apiKey = os.Getenv("NS1_APIKEY") 34 35 return nil 36 } 37 38 func (p *Ns1Provider) GetName() string { 39 return "ns1" 40 } 41 42 func (p *Ns1Provider) GetProviderData(arg ...string) map[string]interface{} { 43 return map[string]interface{}{} 44 } 45 46 func (Ns1Provider) GetResourceConnections() map[string]map[string][]string { 47 return map[string]map[string][]string{} 48 } 49 50 func (p *Ns1Provider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 51 return map[string]terraformutils.ServiceGenerator{ 52 "monitoringjob": &MonitoringJobGenerator{}, 53 "team": &TeamGenerator{}, 54 "zone": &ZoneGenerator{}, 55 } 56 } 57 58 func (p *Ns1Provider) InitService(serviceName string, verbose bool) error { 59 var isSupported bool 60 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 61 return errors.New("ns1: " + serviceName + " not supported service") 62 } 63 p.Service = p.GetSupportedService()[serviceName] 64 p.Service.SetName(serviceName) 65 p.Service.SetVerbose(verbose) 66 p.Service.SetProviderName(p.GetName()) 67 p.Service.SetArgs(map[string]interface{}{ 68 "api_key": p.apiKey, 69 }) 70 return nil 71 }