Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store dashboard widget IDs #815

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had some trouble in the past with widget IDs big enough to require Int64 when represented in Go. I think schema.TypeInt will work (they don't seem to provide an explicitly Int64 version) but I'm not familiar enough to gauge this properly.

Just wanted to put this on your radar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comment: terraform does indeed the right thing, and TypeInt is int64 capable.

Computed: true,
Copy link
Contributor

@matt-miller-ddog matt-miller-ddog Jan 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for 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