provider/datadog #9375: Refactor tags to a list instead of a map. (#10570)

* provider/datadog #9375: Refactor tags to a list instead of a map.
Tags are allowed to be but not restricted to, key value pairs (ie: foo:bar)
but are esssentially strings. This changes allows using, and mixing of tags with
form "foo" and "foo:bar". It also allows using duplicate keys like "foo:bar" and "foo:baz".

* provider/datadog update import test.
This commit is contained in:
Otto Jongerius 2016-12-07 22:05:57 +11:00 committed by Paul Stack
parent 0ab0519edb
commit d06138d052
4 changed files with 23 additions and 47 deletions

View File

@ -48,9 +48,6 @@ resource "datadog_monitor" "foo" {
include_tags = true include_tags = true
require_full_window = true require_full_window = true
locked = false locked = false
tags { tags = ["foo:bar", "bar:baz"]
"foo" = "bar"
"bar" = "baz"
}
} }
` `

View File

@ -119,13 +119,9 @@ func resourceDatadogMonitor() *schema.Resource {
Optional: true, Optional: true,
}, },
"tags": &schema.Schema{ "tags": &schema.Schema{
Type: schema.TypeMap, Type: schema.TypeList,
Optional: true, Optional: true,
Elem: &schema.Schema{ Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeString,
Elem: &schema.Schema{
Type: schema.TypeString},
},
}, },
}, },
} }
@ -193,11 +189,11 @@ func buildMonitorStruct(d *schema.ResourceData) *datadog.Monitor {
} }
if attr, ok := d.GetOk("tags"); ok { if attr, ok := d.GetOk("tags"); ok {
s := make([]string, 0) tags := []string{}
for k, v := range attr.(map[string]interface{}) { for _, s := range attr.([]interface{}) {
s = append(s, fmt.Sprintf("%s:%s", k, v.(string))) tags = append(tags, s.(string))
} }
m.Tags = s m.Tags = tags
} }
return &m return &m
@ -263,10 +259,9 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error
} }
} }
tags := make(map[string]string) tags := []string{}
for _, s := range m.Tags { for _, s := range m.Tags {
tag := strings.Split(s, ":") tags = append(tags, s)
tags[tag[0]] = tag[1]
} }
log.Printf("[DEBUG] monitor: %v", m) log.Printf("[DEBUG] monitor: %v", m)
@ -313,8 +308,8 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
if attr, ok := d.GetOk("tags"); ok { if attr, ok := d.GetOk("tags"); ok {
s := make([]string, 0) s := make([]string, 0)
for k, v := range attr.(map[string]interface{}) { for _, v := range attr.([]interface{}) {
s = append(s, fmt.Sprintf("%s:%s", k, v.(string))) s = append(s, v.(string))
} }
m.Tags = s m.Tags = s
} }

View File

@ -42,9 +42,9 @@ func TestAccDatadogMonitor_Basic(t *testing.T) {
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "false"), "datadog_monitor.foo", "locked", "false"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.foo", "bar"), "datadog_monitor.foo", "tags.0", "foo:bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.bar", "baz"), "datadog_monitor.foo", "tags.1", "baz"),
), ),
}, },
}, },
@ -126,9 +126,9 @@ func TestAccDatadogMonitor_Updated(t *testing.T) {
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "false"), "datadog_monitor.foo", "locked", "false"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.foo", "bar"), "datadog_monitor.foo", "tags.0", "foo:bar"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.bar", "baz"), "datadog_monitor.foo", "tags.1", "baz"),
), ),
}, },
resource.TestStep{ resource.TestStep{
@ -170,9 +170,9 @@ func TestAccDatadogMonitor_Updated(t *testing.T) {
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "locked", "true"), "datadog_monitor.foo", "locked", "true"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.baz", "qux"), "datadog_monitor.foo", "tags.0", "baz:qux"),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"datadog_monitor.foo", "tags.quux", "corge"), "datadog_monitor.foo", "tags.1", "quux"),
), ),
}, },
}, },
@ -285,10 +285,7 @@ resource "datadog_monitor" "foo" {
include_tags = true include_tags = true
require_full_window = true require_full_window = true
locked = false locked = false
tags { tags = ["foo:bar", "baz"]
"foo" = "bar"
"bar" = "baz"
}
} }
` `
const testAccCheckDatadogMonitorConfigNoThresholds = ` const testAccCheckDatadogMonitorConfigNoThresholds = `
@ -338,10 +335,7 @@ resource "datadog_monitor" "foo" {
require_full_window = true require_full_window = true
locked = false locked = false
tags { tags = ["foo:bar", "baz"]
"foo" = "bar"
"bar" = "baz"
}
} }
` `
@ -368,10 +362,7 @@ resource "datadog_monitor" "foo" {
require_full_window = true require_full_window = true
locked = false locked = false
tags { tags = ["foo:bar", "baz"]
"foo" = "bar"
"bar" = "baz"
}
} }
` `
@ -402,10 +393,7 @@ resource "datadog_monitor" "foo" {
silenced { silenced {
"*" = 0 "*" = 0
} }
tags { tags = ["baz:qux", "quux"]
"baz" = "qux"
"quux" = "corge"
}
} }
` `

View File

@ -37,10 +37,7 @@ resource "datadog_monitor" "foo" {
silenced { silenced {
"*" = 0 "*" = 0
} }
tags { tags = ["foo:bar", "baz"]
"foo" = "bar"
"bar" = "baz"
}
} }
``` ```
@ -94,13 +91,12 @@ The following arguments are supported:
from a triggered state. Defaults to false. from a triggered state. Defaults to false.
* `include_tags` (Optional) A boolean indicating whether notifications from this monitor will automatically insert its * `include_tags` (Optional) A boolean indicating whether notifications from this monitor will automatically insert its
triggering tags into the title. Defaults to true. triggering tags into the title. Defaults to true.
* `silenced` (Optional) Each scope will be muted until the given POSIX timestamp or forever if the value is 0.
* `require_full_window` (Optional) A boolean indicating whether this monitor needs a full window of data before it's evaluated. * `require_full_window` (Optional) A boolean indicating whether this monitor needs a full window of data before it's evaluated.
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 * `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
* `silenced` (Optional) Each scope will be muted until the given POSIX timestamp or forever if the value is 0.
To mute the alert completely: To mute the alert completely:
silenced { silenced {