Make datadog message, escalation_message, and query work with heredoc
This commit is contained in:
parent
539cbe2b01
commit
4fcb90814f
|
@ -27,14 +27,23 @@ func resourceDatadogMonitor() *schema.Resource {
|
|||
"message": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: func(val interface{}) string {
|
||||
return strings.TrimSpace(val.(string))
|
||||
},
|
||||
},
|
||||
"escalation_message": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
StateFunc: func(val interface{}) string {
|
||||
return strings.TrimSpace(val.(string))
|
||||
},
|
||||
},
|
||||
"query": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
StateFunc: func(val interface{}) string {
|
||||
return strings.TrimSpace(val.(string))
|
||||
},
|
||||
},
|
||||
"type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
|
@ -296,7 +305,7 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
|
|||
m.Options = o
|
||||
|
||||
if err = client.UpdateMonitor(m); err != nil {
|
||||
return fmt.Errorf("error updating montor: %s", err.Error())
|
||||
return fmt.Errorf("error updating monitor: %s", err.Error())
|
||||
}
|
||||
|
||||
return resourceDatadogMonitorRead(d, meta)
|
||||
|
|
|
@ -121,6 +121,40 @@ func TestAccDatadogMonitor_Updated(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDatadogMonitor_TrimWhitespace(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckDatadogMonitorDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccCheckDatadogMonitorConfigWhitespace,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckDatadogMonitorExists("datadog_monitor.foo"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "name", "name for monitor foo"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "message", "some message Notify: @hipchat-channel"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "type", "metric alert"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "query", "avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "notify_no_data", "false"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "renotify_interval", "60"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "thresholds.ok", "0"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "thresholds.warning", "1"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"datadog_monitor.foo", "thresholds.critical", "2"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckDatadogMonitorDestroy(s *terraform.State) error {
|
||||
client := testAccProvider.Meta().(*datadog.Client)
|
||||
|
||||
|
@ -191,6 +225,34 @@ resource "datadog_monitor" "foo" {
|
|||
}
|
||||
`
|
||||
|
||||
const testAccCheckDatadogMonitorConfigWhitespace = `
|
||||
resource "datadog_monitor" "foo" {
|
||||
name = "name for monitor foo"
|
||||
type = "metric alert"
|
||||
message = <<EOF
|
||||
some message Notify: @hipchat-channel
|
||||
EOF
|
||||
escalation_message = <<EOF
|
||||
the situation has escalated @pagerduty
|
||||
EOF
|
||||
query = <<EOF
|
||||
avg(last_1h):avg:aws.ec2.cpu{environment:foo,host:foo} by {host} > 2
|
||||
EOF
|
||||
thresholds {
|
||||
ok = 0
|
||||
warning = 1
|
||||
critical = 2
|
||||
}
|
||||
|
||||
notify_no_data = false
|
||||
renotify_interval = 60
|
||||
|
||||
notify_audit = false
|
||||
timeout_h = 60
|
||||
include_tags = true
|
||||
}
|
||||
`
|
||||
|
||||
func destroyHelper(s *terraform.State, client *datadog.Client) error {
|
||||
for _, r := range s.RootModule().Resources {
|
||||
i, _ := strconv.Atoi(r.Primary.ID)
|
||||
|
|
Loading…
Reference in New Issue