logdna / terraform-provider-logdna

Terraform provider to simplify creation of views, preset alerts and other resources in LogDNA!
https://registry.terraform.io/providers/logdna/logdna/latest
MIT License
11 stars 12 forks source link

Add support for attaching a Preset Alert to a View #26

Open wosteven opened 3 years ago

wosteven commented 3 years ago

Hey !

How can i associate a view with an alert preset ?

I see that you can define a view and an alert separatly:

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"
}

resource "logdna_alert" "my_alert" {
  name = "My Preset Alert via Terraform"
  email_channel {
    emails          = ["test@logdna.com"]
    immediate       = "false"
    operator        = "presence"
    triggerlimit    = 15
    triggerinterval = "15m"
    terminal        = "true"
    timezone        = "Pacific/Samoa"
  }
}

But how can i make "my_view" use "my_alert" ?

I would expect to see something like:

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"
  **alerts = [ logdna_alert.my_alert ]**
}

I did not find an attribute in logdna_view or logdna_alert that would support that ? Or do i miss something ?

mdeltito commented 3 years ago

Hi @wosteven

Views can have one or more alerting "channels" attached to them, which I think is what you're after. Here's an example of a View that has an email alert channel configured:

https://github.com/logdna/terraform-provider-logdna/blob/main/examples/view_with_email_alert.tf

wosteven commented 3 years ago

Hi @mdeltito , we have seen that i can do that (kind of "inline" channels - specific to the view). But what's the point of being able to create a "logdna_alert" resource if i cannot attach this to a view in TF ? We wanna define a common alert channel and attach this to multiple views. And we only see this to be done atm by re-creating the exact channel in each view.

mdeltito commented 3 years ago

@wosteven ah yes, we do have plans for allowing Preset Alerts to be attached to a View within the provider. Thanks for the clarification!

cc: @alfeng6

david-ly commented 2 years ago

@wosteven we recently added the ability to consume logdna_alert resources managed/created via Terraform as data sources which should support the functionality to define a "common" preset alert and reference it in any # of views. Refer to the docs here.

For your provided example, the HCL implementation would look something like:


resource "logdna_alert" "my_alert" {
  name = "My Preset Alert via Terraform"
  email_channel {
    emails          = ["test@logdna.com"]
    immediate       = "false"
    operator        = "presence"
    triggerlimit    = 15
    triggerinterval = "15m"
    terminal        = "true"
    timezone        = "Pacific/Samoa"
  }
}

data "logdna_alert" "my_alert_data" {
  # the `logdna_alert` resource named my_alert will have its `id` attribute set upon successful creation 
  # so the data is being pulled directly from the remote backend rather than the local config args
  presetid = logdna_alert.my_alert.id 
}

resource "logdna_view" "my_view" {
  name  = "Basic View"
  query = "level:debug my query"

  # populate the relevant channel args by accessing the attribute from the preset alert data
  email_channel = data.logdna_alert.my_alert_data.email_channel
  ...
}
philippfrank commented 2 years ago

@david-ly It seems this does not work for slack channels?

An argument named "slack_channel" is not expected here. Did you mean to define a block of type "slack_channel"?

felipefzdz commented 2 years ago

I've also tried with email_channel and that didn't work either:

An argument named "email_channel" is not expected here. Did you mean to define a block of type "email_channel"?

Might be that the whole preset attaching thing is broken at the moment?

philippfrank commented 2 years ago

@mdeltito @david-ly What's the status on this. It's been this way for months and your documentation is certainly wrong. Is this a bug?

I checked the code: the functionality was added and documented back in '21: https://github.com/logdna/terraform-provider-logdna/commit/c87a6cc7be8fbf70ee2531923580702d08dc80e7

The view's slack_channel attribute is of type schema.ListType: https://github.com/logdna/terraform-provider-logdna/commit/c87a6cc7be8fbf70ee2531923580702d08dc80e7#diff-0b4c49f154f7dc1f04a503de890c274c777876182f3bd5e499113009e172e19fR259

Might that be the issue?