provider/datadog: Allow `tags` to be configured for monitor resources. (#8284)

This commit is contained in:
Otto Jongerius 2016-08-18 17:54:44 +02:00 committed by Paul Stack
parent d7e9a2ecf2
commit 245e211b00
3 changed files with 51 additions and 0 deletions

View File

@ -114,6 +114,15 @@ func resourceDatadogMonitor() *schema.Resource {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
}, },
"tags": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString},
},
},
}, },
} }
} }
@ -179,6 +188,14 @@ func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor {
Options: o, Options: o,
} }
if attr, ok := d.GetOk("tags"); ok {
s := make([]string, 0)
for k, v := range attr.(map[string]interface{}) {
s = append(s, fmt.Sprintf("%s:%s", k, v.(string)))
}
m.Tags = s
}
return &m return &m
} }
@ -244,6 +261,7 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error
d.Set("escalation_message", m.Options.EscalationMessage) d.Set("escalation_message", m.Options.EscalationMessage)
d.Set("silenced", m.Options.Silenced) d.Set("silenced", m.Options.Silenced)
d.Set("include_tags", m.Options.IncludeTags) d.Set("include_tags", m.Options.IncludeTags)
d.Set("tags", m.Tags)
d.Set("require_full_window", m.Options.RequireFullWindow) d.Set("require_full_window", m.Options.RequireFullWindow)
d.Set("locked", m.Options.Locked) d.Set("locked", m.Options.Locked)
@ -271,6 +289,14 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
m.Query = attr.(string) m.Query = attr.(string)
} }
if attr, ok := d.GetOk("tags"); ok {
s := make([]string, 0)
for k, v := range attr.(map[string]interface{}) {
s = append(s, fmt.Sprintf("%s:%s", k, v.(string)))
}
m.Tags = s
}
o := datadog.Options{} o := datadog.Options{}
if attr, ok := d.GetOk("thresholds"); ok { if attr, ok := d.GetOk("thresholds"); ok {
thresholds := attr.(map[string]interface{}) thresholds := attr.(map[string]interface{})

View File

@ -43,6 +43,10 @@ func TestAccDatadogMonitor_Basic(t *testing.T) {
"datadog_monitor.foo", "require_full_window", "true"), "datadog_monitor.foo", "require_full_window", "true"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "false"), "datadog_monitor.foo", "locked", "false"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.foo", "bar"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.bar", "baz"),
), ),
}, },
}, },
@ -89,6 +93,10 @@ func TestAccDatadogMonitor_Updated(t *testing.T) {
"datadog_monitor.foo", "require_full_window", "true"), "datadog_monitor.foo", "require_full_window", "true"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "false"), "datadog_monitor.foo", "locked", "false"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.foo", "bar"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.bar", "baz"),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -129,6 +137,10 @@ func TestAccDatadogMonitor_Updated(t *testing.T) {
"datadog_monitor.foo", "require_full_window", "false"), "datadog_monitor.foo", "require_full_window", "false"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "true"), "datadog_monitor.foo", "locked", "true"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.baz", "qux"),
resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.quux", "corge"),
), ),
}, },
}, },
@ -211,6 +223,10 @@ resource "datadog_monitor" "foo" {
include_tags = true include_tags = true
require_full_window = true require_full_window = true
locked = false locked = false
tags {
"foo" = "bar"
"bar" = "baz"
}
} }
` `
@ -241,6 +257,10 @@ resource "datadog_monitor" "foo" {
silenced { silenced {
"*" = 0 "*" = 0
} }
tags {
"baz" = "qux"
"quux" = "corge"
}
} }
` `

View File

@ -37,6 +37,10 @@ resource "datadog_monitor" "foo" {
silenced { silenced {
"*" = 0 "*" = 0
} }
tags {
"foo" = "bar"
"bar" = "baz"
}
} }
``` ```
@ -78,6 +82,7 @@ The following arguments are supported:
We highly recommend you set this to False for sparse metrics, otherwise some evaluations will be skipped. We highly recommend you set this to False for sparse metrics, otherwise some evaluations will be skipped.
Default: True for "on average", "at all times" and "in total" aggregation. False otherwise. Default: True for "on average", "at all times" and "in total" aggregation. False otherwise.
* `locked` (Optional) A boolean indicating whether changes to to this monitor should be restricted to the creator or admins. Defaults to False. * `locked` (Optional) A boolean indicating whether changes to to this monitor should be restricted to the creator or admins. Defaults to False.
* `tags` (Optional) A list of tags to associate with your monitor. This can help you categorize and filter monitors in the manage monitors page of the UI. Note: it's not currently possible to filter by these tags when querying via the API
To mute the alert completely: To mute the alert completely: