From 245e211b00e2b8a18df5a374bab183c827fbbeaf Mon Sep 17 00:00:00 2001 From: Otto Jongerius Date: Thu, 18 Aug 2016 17:54:44 +0200 Subject: [PATCH] provider/datadog: Allow `tags` to be configured for monitor resources. (#8284) --- .../datadog/resource_datadog_monitor.go | 26 +++++++++++++++++++ .../datadog/resource_datadog_monitor_test.go | 20 ++++++++++++++ .../providers/datadog/r/monitor.html.markdown | 5 ++++ 3 files changed, 51 insertions(+) diff --git a/builtin/providers/datadog/resource_datadog_monitor.go b/builtin/providers/datadog/resource_datadog_monitor.go index 790bed6ec..652e6138e 100644 --- a/builtin/providers/datadog/resource_datadog_monitor.go +++ b/builtin/providers/datadog/resource_datadog_monitor.go @@ -114,6 +114,15 @@ func resourceDatadogMonitor() *schema.Resource { Type: schema.TypeBool, 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, } + 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 } @@ -244,6 +261,7 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error d.Set("escalation_message", m.Options.EscalationMessage) d.Set("silenced", m.Options.Silenced) d.Set("include_tags", m.Options.IncludeTags) + d.Set("tags", m.Tags) d.Set("require_full_window", m.Options.RequireFullWindow) d.Set("locked", m.Options.Locked) @@ -271,6 +289,14 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro 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{} if attr, ok := d.GetOk("thresholds"); ok { thresholds := attr.(map[string]interface{}) diff --git a/builtin/providers/datadog/resource_datadog_monitor_test.go b/builtin/providers/datadog/resource_datadog_monitor_test.go index 61d058484..09b5b37b5 100644 --- a/builtin/providers/datadog/resource_datadog_monitor_test.go +++ b/builtin/providers/datadog/resource_datadog_monitor_test.go @@ -43,6 +43,10 @@ func TestAccDatadogMonitor_Basic(t *testing.T) { "datadog_monitor.foo", "require_full_window", "true"), resource.TestCheckResourceAttr( "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"), resource.TestCheckResourceAttr( "datadog_monitor.foo", "locked", "false"), + resource.TestCheckResourceAttr( + "datadog_monitor.foo", "tags.foo", "bar"), + resource.TestCheckResourceAttr( + "datadog_monitor.foo", "tags.bar", "baz"), ), }, resource.TestStep{ @@ -129,6 +137,10 @@ func TestAccDatadogMonitor_Updated(t *testing.T) { "datadog_monitor.foo", "require_full_window", "false"), resource.TestCheckResourceAttr( "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 require_full_window = true locked = false + tags { + "foo" = "bar" + "bar" = "baz" + } } ` @@ -241,6 +257,10 @@ resource "datadog_monitor" "foo" { silenced { "*" = 0 } + tags { + "baz" = "qux" + "quux" = "corge" + } } ` diff --git a/website/source/docs/providers/datadog/r/monitor.html.markdown b/website/source/docs/providers/datadog/r/monitor.html.markdown index 8cc6c6876..3347c0bd3 100644 --- a/website/source/docs/providers/datadog/r/monitor.html.markdown +++ b/website/source/docs/providers/datadog/r/monitor.html.markdown @@ -37,6 +37,10 @@ resource "datadog_monitor" "foo" { silenced { "*" = 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. 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. +* `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: