-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from terraform-providers/dashboard_and_dashboa…
…rd_groups added dashboards and dashboard groups resource and import functionality
- Loading branch information
Showing
23 changed files
with
1,221 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package logicmonitor | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
lmclient "github.com/logicmonitor/lm-sdk-go/client" | ||
"github.com/logicmonitor/lm-sdk-go/client/lm" | ||
) | ||
|
||
// terraform data source to look up dashboard groups | ||
func dataSourceFindDashboards() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: findDashboards, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"filters": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"property": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"operator": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"custom_property_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"custom_property_value": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"size": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 50, | ||
}, | ||
"offset": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 0, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// function to find dashboard with certain filters | ||
func findDashboards(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*lmclient.LMSdkGo) | ||
filter := getFilters(d) | ||
size := int32(d.Get("size").(int)) | ||
offset := int32(d.Get("offset").(int)) | ||
|
||
params := lm.NewGetDashboardListParams() | ||
params.SetFilter(&filter) | ||
params.SetOffset(&offset) | ||
params.SetSize(&size) | ||
|
||
//looks for dashboard group | ||
restDashboardGroupPaginationResponse, err := client.LM.GetDashboardList(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var dashboardIds []string | ||
for _, d := range restDashboardGroupPaginationResponse.Payload.Items { | ||
log.Printf("Found dashboard with filter %q", filter) | ||
dashboardIds = append(dashboardIds, strconv.Itoa(int(d.ID))) | ||
} | ||
|
||
if len(dashboardIds) > 0 { | ||
//comma separated string of device Ids | ||
var ids = strings.Join(dashboardIds, ",") | ||
d.SetId(ids) | ||
} else { | ||
err := fmt.Errorf("Found no dashboard with filter %s", filter) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package logicmonitor | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
lmclient "github.com/logicmonitor/lm-sdk-go/client" | ||
"github.com/logicmonitor/lm-sdk-go/client/lm" | ||
) | ||
|
||
// terraform data source to look up dashboard groups | ||
func dataSourceFindDashboardGroups() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: findDashboardGroup, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"filters": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"property": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"operator": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"custom_property_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"custom_property_value": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"size": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 50, | ||
}, | ||
"offset": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: 0, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// function to find dashboard groups with certain filters | ||
func findDashboardGroup(d *schema.ResourceData, m interface{}) error { | ||
client := m.(*lmclient.LMSdkGo) | ||
filter := getFilters(d) | ||
size := int32(d.Get("size").(int)) | ||
offset := int32(d.Get("offset").(int)) | ||
|
||
params := lm.NewGetDashboardGroupListParams() | ||
params.SetFilter(&filter) | ||
params.SetOffset(&offset) | ||
params.SetSize(&size) | ||
|
||
//looks for dashboard group | ||
restDashboardGroupPaginationResponse, err := client.LM.GetDashboardGroupList(params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var dashboardIds []string | ||
for _, d := range restDashboardGroupPaginationResponse.Payload.Items { | ||
log.Printf("Found dashboard group with filter %q", filter) | ||
dashboardIds = append(dashboardIds, strconv.Itoa(int(d.ID))) | ||
} | ||
|
||
if len(dashboardIds) > 0 { | ||
//comma separated string of device Ids | ||
var ids = strings.Join(dashboardIds, ",") | ||
d.SetId(ids) | ||
} else { | ||
err := fmt.Errorf("Found no dashboard groups with filter %s", filter) | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package logicmonitor | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
lmclient "github.com/logicmonitor/lm-sdk-go/client" | ||
) | ||
|
||
func TestAccCheckLogicMonitorDashboardGroupDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: TestAccCheckLogicMonitorDashboardGroupDataSourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDashboardGroupID("data.logicmonitor_dashboard_group.board1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDashboardGroupID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find logicmonitor dashboard group data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("logicmonitor dashgroup group data source ID not set") | ||
} | ||
|
||
client := testAccProvider.Meta().(*lmclient.LMSdkGo) | ||
if err := testDashboardGroupExistsHelper(s, client); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const TestAccCheckLogicMonitorDashboardGroupDataSourceConfig = ` | ||
resource "logicmonitor_dashboard_group" "group1" { | ||
name = "NewTestDashboardGroup" | ||
description = "this is a test for creating dashboard groups" | ||
} | ||
data "logicmonitor_dashboard_group" "board1" { | ||
filters { | ||
property = "name" | ||
operator = ":" | ||
value = "${logicmonitor_dashboard_group.group1.name}" | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package logicmonitor | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
lmclient "github.com/logicmonitor/lm-sdk-go/client" | ||
) | ||
|
||
func TestAccCheckLogicMonitorDashboardDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: TestAccCheckLogicMonitorDashboardDataSourceConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckDashboardID("data.logicmonitor_dashboard.board1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckDashboardID(n string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[n] | ||
if !ok { | ||
return fmt.Errorf("Can't find logicmonitor dashboard data source: %s", n) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("logicmonitor dash data source ID not set") | ||
} | ||
|
||
client := testAccProvider.Meta().(*lmclient.LMSdkGo) | ||
if err := testDashboardExistsHelper(s, client); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
const TestAccCheckLogicMonitorDashboardDataSourceConfig = ` | ||
resource "logicmonitor_dashboard" "brd" { | ||
name = "Kobe Doin Work" | ||
description = "Another Kobe Tribute Dashboard" | ||
} | ||
data "logicmonitor_dashboard" "board1" { | ||
filters { | ||
property = "name" | ||
operator = ":" | ||
value = "${logicmonitor_dashboard.brd.name}" | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.