github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/fastly/fastly_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 fastly 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type FastlyProvider struct { //nolint 25 terraformutils.Provider 26 customerID string 27 apiKey string 28 } 29 30 func (p *FastlyProvider) Init(args []string) error { 31 if os.Getenv("FASTLY_API_KEY") == "" { 32 return errors.New("set FASTLY_API_KEY env var") 33 } 34 p.apiKey = os.Getenv("FASTLY_API_KEY") 35 36 if os.Getenv("FASTLY_CUSTOMER_ID") == "" { 37 return errors.New("set FASTLY_CUSTOMER_ID env var") 38 } 39 p.customerID = os.Getenv("FASTLY_CUSTOMER_ID") 40 41 return nil 42 } 43 44 func (p *FastlyProvider) GetName() string { 45 return "fastly" 46 } 47 48 func (p *FastlyProvider) GetProviderData(arg ...string) map[string]interface{} { 49 return map[string]interface{}{ 50 "provider": map[string]interface{}{ 51 "fastly": map[string]interface{}{ 52 "customer_id": p.customerID, 53 }, 54 }, 55 } 56 } 57 58 func (FastlyProvider) GetResourceConnections() map[string]map[string][]string { 59 return map[string]map[string][]string{} 60 } 61 62 func (p *FastlyProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 63 return map[string]terraformutils.ServiceGenerator{ 64 "service_v1": &ServiceV1Generator{}, 65 "user": &UserGenerator{}, 66 } 67 } 68 69 func (p *FastlyProvider) InitService(serviceName string, verbose bool) error { 70 var isSupported bool 71 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 72 return errors.New("fastly: " + serviceName + " not supported service") 73 } 74 p.Service = p.GetSupportedService()[serviceName] 75 p.Service.SetName(serviceName) 76 p.Service.SetVerbose(verbose) 77 p.Service.SetProviderName(p.GetName()) 78 p.Service.SetArgs(map[string]interface{}{ 79 "customer_id": p.customerID, 80 "api_key": p.apiKey, 81 }) 82 return nil 83 }