github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/equinixmetal/equinixmetal_provider.go (about) 1 // Copyright 2021 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 equinixmetal 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type EquinixMetalProvider struct { //nolint 25 terraformutils.Provider 26 authToken string 27 projectID string 28 } 29 30 func (p *EquinixMetalProvider) Init(args []string) error { 31 if os.Getenv("PACKET_AUTH_TOKEN") == "" { 32 return errors.New("set PACKET_AUTH_TOKEN env var") 33 } 34 p.authToken = os.Getenv("PACKET_AUTH_TOKEN") 35 36 if os.Getenv("METAL_PROJECT_ID") == "" { 37 return errors.New("set METAL_PROJECT_ID env var") 38 } 39 p.projectID = os.Getenv("METAL_PROJECT_ID") 40 41 return nil 42 } 43 44 func (p *EquinixMetalProvider) GetName() string { 45 return "metal" 46 } 47 48 func (p *EquinixMetalProvider) GetProviderData(arg ...string) map[string]interface{} { 49 return map[string]interface{}{} 50 } 51 52 func (EquinixMetalProvider) GetResourceConnections() map[string]map[string][]string { 53 return map[string]map[string][]string{} 54 } 55 56 func (p *EquinixMetalProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 57 return map[string]terraformutils.ServiceGenerator{ 58 "device": &DeviceGenerator{}, 59 "sshkey": &SSHKeyGenerator{}, 60 "spotmarketrequest": &SpotMarketRequestGenerator{}, 61 "volume": &VolumeGenerator{}, 62 } 63 } 64 65 func (p *EquinixMetalProvider) InitService(serviceName string, verbose bool) error { 66 var isSupported bool 67 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 68 return errors.New("equinixmetal: " + serviceName + " not supported service") 69 } 70 p.Service = p.GetSupportedService()[serviceName] 71 p.Service.SetName(serviceName) 72 p.Service.SetVerbose(verbose) 73 p.Service.SetProviderName(p.GetName()) 74 p.Service.SetArgs(map[string]interface{}{ 75 "auth_token": p.authToken, 76 "project_id": p.projectID, 77 }) 78 return nil 79 }