github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/rabbitmq/rabbitmq_provider.go (about) 1 // Copyright 2018 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 rabbitmq 16 17 import ( 18 "errors" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/zclconf/go-cty/cty" 22 ) 23 24 type RBTProvider struct { //nolint 25 terraformutils.Provider 26 endpoint string 27 username string 28 password string 29 } 30 31 func (p *RBTProvider) Init(args []string) error { 32 p.endpoint = args[0] 33 p.username = args[1] 34 p.password = args[2] 35 return nil 36 } 37 38 func (p *RBTProvider) GetName() string { 39 return "rabbitmq" 40 } 41 42 func (p *RBTProvider) GetProviderData(arg ...string) map[string]interface{} { 43 return map[string]interface{}{} 44 } 45 46 func (p *RBTProvider) GetConfig() cty.Value { 47 return cty.ObjectVal(map[string]cty.Value{ 48 "endpoint": cty.StringVal(p.endpoint), 49 "username": cty.StringVal(p.username), 50 "password": cty.StringVal(p.password), 51 }) 52 } 53 54 func (p *RBTProvider) GetBasicConfig() cty.Value { 55 return p.GetConfig() 56 } 57 58 func (p *RBTProvider) InitService(serviceName string, verbose bool) error { 59 var isSupported bool 60 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 61 return errors.New(p.GetName() + ": " + 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 "endpoint": p.endpoint, 69 "username": p.username, 70 "password": p.password, 71 }) 72 return nil 73 } 74 75 func (p *RBTProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 76 return map[string]terraformutils.ServiceGenerator{ 77 "bindings": &BindingGenerator{}, 78 "exchanges": &ExchangeGenerator{}, 79 "permissions": &PermissionsGenerator{}, 80 "policies": &PolicyGenerator{}, 81 "queues": &QueueGenerator{}, 82 "users": &UserGenerator{}, 83 "vhosts": &VhostGenerator{}, 84 "shovels": &ShovelGenerator{}, 85 } 86 } 87 88 func (RBTProvider) GetResourceConnections() map[string]map[string][]string { 89 return map[string]map[string][]string{ 90 "bindings": { 91 "exchanges": []string{"source", "name", "destination", "name"}, 92 "queues": []string{"destination", "name"}, 93 "vhosts": []string{"vhost", "self_link"}, 94 }, 95 "exchanges": { 96 "vhosts": []string{"vhost", "self_link"}, 97 }, 98 "shovels": { 99 "vhosts": []string{"vhost", "self_link"}, 100 }, 101 "permissions": { 102 "users": []string{"user", "self_link"}, 103 "vhosts": []string{"vhost", "self_link"}, 104 }, 105 "policies": { 106 "vhosts": []string{"vhost", "self_link"}, 107 }, 108 "queues": { 109 "vhosts": []string{"vhost", "self_link"}, 110 }, 111 } 112 }