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

Using "here doc" syntax with datadog_monitor.message causes plan to always show changes #5642

Closed
billputer opened this issue Mar 15, 2016 · 7 comments

Comments

@billputer
Copy link

With the datadog_monitor resource, I'm trying to set a multi-line message using the "here doc" syntax.

message = <<MESSAGE
The ${var.env} RDS instance is low on disk space.
Notify: ${var.notify}
MESSAGE

This applies cleanly, but it appears that Datadog trims trailing newlines, so that resource always shows as changed.

~ module.datadog.datadog_monitor.rds_disk
    message: "The staging RDS instance is low on disk space.\nNotify: @all" => "The staging RDS instance is low on disk space.\nNotify: @all\n"

Unfortunately, I can't find a clean way to set a multiline message without a trailing newline. I can work around this by either writing the message as a one-line string with "\n" inline, or by putting the message in a template, but both of those decrease readability. I'd like to be able to use multiline strings with the datadog_monitor resource.

@billputer
Copy link
Author

My go-fu is poor, but I'll take a look at the provider, it might be fairly easy to have it trim newlines before comparing to the result from the Datadog API.

@billputer
Copy link
Author

I was able to get the desired behavior by adding the following StateFunc.

diff --git a/builtin/providers/datadog/resource_datadog_monitor.go b/builtin/providers/datadog/resource_datadog_monitor.go
index af2b89f..79a28c6 100644
--- a/builtin/providers/datadog/resource_datadog_monitor.go
+++ b/builtin/providers/datadog/resource_datadog_monitor.go
@@ -27,6 +27,9 @@ 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,

I've also verified that the Datadog automatically trims leading and trailing white space, so adding this StateFunc should cause the message field to match. I'm going to check if any other fields on the datadog_monitor require normalization, and then put together a PR.

I'll also look around to see if there's any good examples of testing this type of StateFunc transformation, since I'm not really sure the canonical way to test this.

@ojongerius
Copy link
Contributor

Awesome, thanks for taking this on!

@multilinear
Copy link

I ran in to the same issue, so I wrote a patch for it including a couple of other fields and tests. ^

@stack72
Copy link
Contributor

stack72 commented Mar 31, 2016

Hi @billputer this has been merged in #5788

Thanks for the report!

@stack72 stack72 closed this as completed Mar 31, 2016
@ojongerius
Copy link
Contributor

Thanks @stack72

@ghost
Copy link

ghost commented Apr 27, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants