github.com/GoogleCloudPlatform/terraformer@v0.8.18/cmd/provider_cmd_logzio.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 package cmd 15 16 import ( 17 "errors" 18 "os" 19 20 logzio_terraforming "github.com/GoogleCloudPlatform/terraformer/providers/logzio" 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/spf13/cobra" 23 ) 24 25 const ( 26 defaultBaseURL = "https://api.logz.io" 27 ) 28 29 func newCmdLogzioImporter(options ImportOptions) *cobra.Command { 30 cmd := &cobra.Command{ 31 Use: "logzio", 32 Short: "Import current state to Terraform configuration from Logz.io", 33 Long: "Import current state to Terraform configuration from Logz.io", 34 RunE: func(cmd *cobra.Command, args []string) error { 35 token := os.Getenv("LOGZIO_API_TOKEN") 36 if len(token) == 0 { 37 return errors.New("API Token for Logz.io must be set through `LOGZIO_API_TOKEN` env var") 38 } 39 baseURL := os.Getenv("LOGZIO_BASE_URL") 40 if len(baseURL) == 0 { 41 baseURL = defaultBaseURL 42 } 43 44 provider := newLogzioProvider() 45 err := Import(provider, options, []string{token, baseURL}) 46 if err != nil { 47 return err 48 } 49 return nil 50 }, 51 } 52 cmd.AddCommand(listCmd(newLogzioProvider())) 53 baseProviderFlags(cmd.PersistentFlags(), &options, "repository", "alert=id1:id2:id4") 54 return cmd 55 } 56 57 func newLogzioProvider() terraformutils.ProviderGenerator { 58 return &logzio_terraforming.LogzioProvider{} 59 }