github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/linode/linode_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 linode 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type LinodeProvider struct { //nolint 25 terraformutils.Provider 26 token string 27 } 28 29 func (p *LinodeProvider) Init(args []string) error { 30 if os.Getenv("LINODE_TOKEN") == "" { 31 return errors.New("set LINODE_TOKEN env var") 32 } 33 p.token = os.Getenv("LINODE_TOKEN") 34 35 return nil 36 } 37 38 func (p *LinodeProvider) GetName() string { 39 return "linode" 40 } 41 42 func (p *LinodeProvider) GetProviderData(arg ...string) map[string]interface{} { 43 return map[string]interface{}{} 44 } 45 46 func (LinodeProvider) GetResourceConnections() map[string]map[string][]string { 47 return map[string]map[string][]string{} 48 } 49 50 func (p *LinodeProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 51 return map[string]terraformutils.ServiceGenerator{ 52 "domain": &DomainGenerator{}, 53 "image": &ImageGenerator{}, 54 "instance": &InstanceGenerator{}, 55 "nodebalancer": &NodeBalancerGenerator{}, 56 "rdns": &RDNSGenerator{}, 57 "sshkey": &SSHKeyGenerator{}, 58 "stackscript": &StackScriptGenerator{}, 59 "token": &TokenGenerator{}, 60 "volume": &VolumeGenerator{}, 61 } 62 } 63 64 func (p *LinodeProvider) InitService(serviceName string, verbose bool) error { 65 var isSupported bool 66 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 67 return errors.New("linode: " + serviceName + " not supported service") 68 } 69 p.Service = p.GetSupportedService()[serviceName] 70 p.Service.SetName(serviceName) 71 p.Service.SetVerbose(verbose) 72 p.Service.SetProviderName(p.GetName()) 73 p.Service.SetArgs(map[string]interface{}{ 74 "token": p.token, 75 }) 76 return nil 77 }