github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_rabbitmq.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 cmd 16 17 import ( 18 "os" 19 20 rabbitmq_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/rabbitmq" 21 22 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 23 "github.com/spf13/cobra" 24 ) 25 26 const ( 27 defaultRabbitMQEndpoint = "http://localhost:15672" 28 ) 29 30 func newCmdRabbitMQImporter(options ImportOptions) *cobra.Command { 31 cmd := &cobra.Command{ 32 Use: "rabbitmq", 33 Short: "Import current state to Terraform configuration from RabbitMQ", 34 Long: "Import current state to Terraform configuration from RabbitMQ", 35 RunE: func(cmd *cobra.Command, args []string) error { 36 endpoint := os.Getenv("RABBITMQ_SERVER_URL") 37 if len(endpoint) == 0 { 38 endpoint = defaultRabbitMQEndpoint 39 } 40 username := os.Getenv("RABBITMQ_USERNAME") 41 password := os.Getenv("RABBITMQ_PASSWORD") 42 provider := newRabbitMQProvider() 43 err := Import(provider, options, []string{endpoint, username, password}) 44 if err != nil { 45 return err 46 } 47 return nil 48 }, 49 } 50 51 cmd.AddCommand(listCmd(newRabbitMQProvider())) 52 baseProviderFlags(cmd.PersistentFlags(), &options, "vhosts", "type=id1:id2:id4") 53 return cmd 54 } 55 56 func newRabbitMQProvider() terraformutils.ProviderGenerator { 57 return &rabbitmq_terraforming.RBTProvider{} 58 }