github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/newrelic/infra.go (about) 1 // Copyright 2019 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 newrelic 16 17 import ( 18 "fmt" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 newrelic "github.com/paultyng/go-newrelic/v4/api" 22 ) 23 24 type InfraGenerator struct { 25 NewRelicService 26 } 27 28 func (g *InfraGenerator) createAlertInfraConditionResources(client *newrelic.Client, infraClient *newrelic.InfraClient) error { 29 alertPolicies, err := client.ListAlertPolicies() 30 if err != nil { 31 return err 32 } 33 34 for _, alertPolicy := range alertPolicies { 35 alertInfraConditions, err := infraClient.ListAlertInfraConditions(alertPolicy.ID) 36 if err != nil { 37 return err 38 } 39 for _, alertInfraCondition := range alertInfraConditions { 40 g.Resources = append(g.Resources, terraformutils.NewResource( 41 fmt.Sprintf("%d:%d", alertPolicy.ID, alertInfraCondition.ID), 42 fmt.Sprintf("%s-%d", normalizeResourceName(alertInfraCondition.Name), alertInfraCondition.ID), 43 "newrelic_infra_alert_condition", 44 g.ProviderName, 45 map[string]string{ 46 "type": alertInfraCondition.Type, 47 }, 48 []string{}, 49 map[string]interface{}{})) 50 } 51 } 52 return nil 53 } 54 55 func (g *InfraGenerator) InitResources() error { 56 infraClient, err := g.InfraClient() 57 if err != nil { 58 return err 59 } 60 61 client, err := g.Client() 62 if err != nil { 63 return err 64 } 65 66 err = g.createAlertInfraConditionResources(client, infraClient) 67 if err != nil { 68 return err 69 } 70 71 return nil 72 }