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

Don't allow empty content in note widget #607

Merged
merged 5 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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: 4 additions & 2 deletions datadog/resource_datadog_dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func resourceDatadogDashboard() *schema.Resource {
Expand Down Expand Up @@ -2905,8 +2906,9 @@ func buildTerraformManageStatusDefinition(datadogDefinition datadogV1.MonitorSum
func getNoteDefinitionSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"content": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"background_color": {
Type: schema.TypeString,
Expand Down
34 changes: 34 additions & 0 deletions datadog/resource_datadog_dashboard_note_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package datadog

import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

// JSON export used as test scenario
Expand Down Expand Up @@ -62,6 +65,21 @@ resource "datadog_dashboard" "note_dashboard" {
}
`

const datadogDashboardNoteConfigNoContent = `
resource "datadog_dashboard" "note_dashboard" {
title = "Acceptance Test Notes Widget Dashboard"
description = "Created using the Datadog provider in Terraform"
layout_type = "ordered"
is_read_only = "true"
widget {
note_definition {
content = ""
}
}
}
`

var datadogDashboardNoteAsserts = []string{
"description = Created using the Datadog provider in Terraform",
"widget.0.note_definition.0.content = This is a note widget",
Expand All @@ -83,3 +101,19 @@ func TestAccDatadogDashboardNote(t *testing.T) {
func TestAccDatadogDashboardNote_import(t *testing.T) {
testAccDatadogDashboardWidgetUtil_import(t, datadogDashboardNoteConfig, "datadog_dashboard.note_dashboard")
}

func TestAccDatadogDashboardNoteContentError(t *testing.T) {
accProviders, cleanup := testAccProviders(t, initRecorder(t))
defer cleanup(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: accProviders,
Steps: []resource.TestStep{
{
Config: datadogDashboardNoteConfigNoContent,
ExpectError: regexp.MustCompile("expected \"widget.0.note_definition.0.content\" to not be an empty string"),
},
},
})
}