github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/logzio/alerts.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 logzio 16 17 import ( 18 "strconv" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 22 "github.com/jonboydell/logzio_client/alerts" 23 ) 24 25 type AlertsGenerator struct { 26 LogzioService 27 } 28 29 // Generate Terraform Resources from Logzio API, 30 func (g *AlertsGenerator) InitResources() error { 31 var client *alerts.AlertsClient 32 client, _ = alerts.New(g.Args["api_token"].(string), g.Args["base_url"].(string)) 33 34 alerts, err := client.ListAlerts() 35 if err != nil { 36 return err 37 } 38 allowedEmptyValues := []string{"alert_notification_endpoints.#", "notification_emails.#"} 39 for _, alert := range alerts { 40 g.Resources = append(g.Resources, terraformutils.NewSimpleResource( 41 strconv.FormatInt(alert.AlertId, 10), 42 createSlug(alert.Title+"-"+strconv.FormatInt(alert.AlertId, 10)), 43 "logzio_alert", 44 "logzio", 45 allowedEmptyValues, 46 )) 47 } 48 return nil 49 }