github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/datadog/dashboard_list.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 datadog 16 17 import ( 18 "context" 19 "fmt" 20 "strconv" 21 22 datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog" 23 24 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 25 ) 26 27 var ( 28 // DashboardListAllowEmptyValues ... 29 DashboardListAllowEmptyValues = []string{} 30 ) 31 32 // DashboardListGenerator ... 33 type DashboardListGenerator struct { 34 DatadogService 35 } 36 37 func (g *DashboardListGenerator) createResources(dashboardLists []datadogV1.DashboardList) []terraformutils.Resource { 38 resources := []terraformutils.Resource{} 39 for _, dashboardList := range dashboardLists { 40 resourceID := strconv.FormatInt(dashboardList.GetId(), 10) 41 resources = append(resources, g.createResource(resourceID)) 42 } 43 44 return resources 45 } 46 47 func (g *DashboardListGenerator) createResource(dashboardListID string) terraformutils.Resource { 48 return terraformutils.NewSimpleResource( 49 dashboardListID, 50 fmt.Sprintf("dashboard_list_%s", dashboardListID), 51 "datadog_dashboard_list", 52 "datadog", 53 DashboardListAllowEmptyValues, 54 ) 55 } 56 57 // InitResources Generate TerraformResources from Datadog API, 58 // from each dashboard_list create 1 TerraformResource. 59 // Need DashboardList ID as ID for terraform resource 60 func (g *DashboardListGenerator) InitResources() error { 61 datadogClientV1 := g.Args["datadogClientV1"].(*datadogV1.APIClient) 62 authV1 := g.Args["authV1"].(context.Context) 63 64 dlResponse, _, err := datadogClientV1.DashboardListsApi.ListDashboardLists(authV1) 65 if err != nil { 66 return err 67 } 68 g.Resources = g.createResources(dlResponse.GetDashboardLists()) 69 return nil 70 }