Skip to content

Commit

Permalink
Store dashboard widget IDs (#815)
Browse files Browse the repository at this point in the history
This adds a new attribute to dashboard widgets to store their IDs for
future references.

Closes #301
  • Loading branch information
therve authored Jan 11, 2021
1 parent 38540bd commit 02d8ec9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 6 additions & 0 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ func getNonGroupWidgetSchema() map[string]*schema.Schema {
Schema: getWidgetLayoutSchema(),
},
},
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "The ID of the widget.",
},
// A widget should implement exactly one of the following definitions
"alert_graph_definition": {
Type: schema.TypeList,
Expand Down Expand Up @@ -903,6 +908,7 @@ func buildTerraformWidget(datadogWidget datadogV1.Widget) (map[string]interface{
if v, ok := datadogWidget.GetLayoutOk(); ok {
terraformWidget["layout"] = buildTerraformWidgetLayout(*v)
}
terraformWidget["id"] = datadogWidget.GetId()

// Build definition
widgetDefinition := datadogWidget.GetDefinition()
Expand Down
18 changes: 12 additions & 6 deletions datadog/resource_datadog_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,11 @@ func TestAccDatadogDashboard_update(t *testing.T) {
asserts = append(asserts, fmt.Sprintf("title = %s", dbName))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)
checks := testCheckResourceAttrs("datadog_dashboard.ordered_dashboard", checkDashboardExists(accProvider), asserts)
for i := 0; i < 16; i++ {
checks = append(checks, resource.TestCheckResourceAttrSet(
"datadog_dashboard.ordered_dashboard", fmt.Sprintf("widget.%d.id", i)))
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -1194,9 +1199,7 @@ func TestAccDatadogDashboard_update(t *testing.T) {
Steps: []resource.TestStep{
{
Config: datadogOrderedDashboardConfig(dbName),
Check: resource.ComposeTestCheckFunc(
testCheckResourceAttrs("datadog_dashboard.ordered_dashboard", checkDashboardExists(accProvider), asserts)...,
),
Check: resource.ComposeTestCheckFunc(checks...),
},
},
})
Expand All @@ -1209,6 +1212,11 @@ func TestAccDatadogFreeDashboard(t *testing.T) {
asserts = append(asserts, fmt.Sprintf("title = %s", dbName))
defer cleanup(t)
accProvider := testAccProvider(t, accProviders)
checks := testCheckResourceAttrs("datadog_dashboard.free_dashboard", checkDashboardExists(accProvider), asserts)
for i := 0; i < 8; i++ {
checks = append(checks, resource.TestCheckResourceAttrSet(
"datadog_dashboard.free_dashboard", fmt.Sprintf("widget.%d.id", i)))
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -1217,9 +1225,7 @@ func TestAccDatadogFreeDashboard(t *testing.T) {
Steps: []resource.TestStep{
{
Config: datadogFreeDashboardConfig(dbName),
Check: resource.ComposeTestCheckFunc(
testCheckResourceAttrs("datadog_dashboard.free_dashboard", checkDashboardExists(accProvider), asserts)...,
),
Check: resource.ComposeTestCheckFunc(checks...),
},
},
})
Expand Down

0 comments on commit 02d8ec9

Please sign in to comment.