github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/rabbitmq/queue.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 "encoding/json" 19 "fmt" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type QueueGenerator struct { 25 RBTService 26 } 27 28 type Queue struct { 29 Name string `json:"name"` 30 Vhost string `json:"vhost"` 31 } 32 33 type Queues []Queue 34 35 var QueueAllowEmptyValues = []string{} 36 var QueueAdditionalFields = map[string]interface{}{} 37 38 func (g QueueGenerator) createResources(queues Queues) []terraformutils.Resource { 39 var resources []terraformutils.Resource 40 for _, queue := range queues { 41 resources = append(resources, terraformutils.NewResource( 42 fmt.Sprintf("%s@%s", queue.Name, queue.Vhost), 43 fmt.Sprintf("queue_%s_%s", normalizeResourceName(queue.Vhost), normalizeResourceName(queue.Name)), 44 "rabbitmq_queue", 45 "rabbitmq", 46 map[string]string{ 47 "name": queue.Name, 48 "vhost": queue.Vhost, 49 }, 50 QueueAllowEmptyValues, 51 QueueAdditionalFields, 52 )) 53 } 54 return resources 55 } 56 57 func (g *QueueGenerator) InitResources() error { 58 body, err := g.generateRequest("/api/queues?columns=name,vhost") 59 if err != nil { 60 return err 61 } 62 var queues Queues 63 err = json.Unmarshal(body, &queues) 64 if err != nil { 65 return err 66 } 67 g.Resources = g.createResources(queues) 68 return nil 69 }