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

New Resource: azurerm_monitor_metric_alert #2007

Closed
mmclane opened this issue Oct 2, 2018 · 9 comments
Closed

New Resource: azurerm_monitor_metric_alert #2007

mmclane opened this issue Oct 2, 2018 · 9 comments

Comments

@mmclane
Copy link

mmclane commented Oct 2, 2018

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

I can currently use terraform to create an azurerm_metric_alertrule and azurerm_monitor_action_group separately. But I can't create an azurerm_metric_alertrule and point it at an action group (either the one created by terraform or an existing one). This seems like a huge oversight.

New or Affected Resource(s)

  • azurerm_metric_alertrule
  • azurerm_monitor_action_group

Potential Terraform Configuration

resource "azurerm_metric_alertrule" "test" {
  name = "${azurerm_virtual_machine.test.name}-cpu"
  resource_group_name = "${azurerm_resource_group.test.name}"
  location = "${azurerm_resource_group.test.location}"

  description = "An alert rule to watch the metric Percentage CPU"

  enabled = true

  resource_id = "${azurerm_virtual_machine.test.id}"
  metric_name = "Percentage CPU"
  operator = "GreaterThan"
  threshold = 75
  aggregation = "Average"
  period = "PT5M"

  email_action {
    send_to_service_owners = false
    custom_emails = [
      "[email protected]",
    ]
  }

  webhook_action {
    service_uri = "https://example.com/some-url"
      properties = {
        severity = "incredible"
        acceptance_test = "true"
      }
  }
}
resource "azurerm_resource_group" "test" {
  name     = "monitoring-resources"
  location = "West US"
}

resource "azurerm_monitor_action_group" "test" {
  name                = "CriticalAlertsAction"
  resource_group_name = "${azurerm_resource_group.test.name}"
  short_name          = "p0action"

  email_receiver {
    name          = "sendtoadmin"
    email_address = "[email protected]"
  }

  email_receiver {
    name          = "sendtodevops"
    email_address = "[email protected]"
  }

  sms_receiver {
    name         = "oncallmsg"
    country_code = "1"
    phone_number = "1231231234"
  }

  webhook_receiver {
    name        = "callmyapiaswell"
    service_uri = "http://example.com/alert"
  }
}

References

@mmclane
Copy link
Author

mmclane commented Oct 2, 2018

Well, as it turns out I need this to support the new alert rules, not the classic ones.

@JunyiYi
Copy link

JunyiYi commented Oct 3, 2018

Hi @mmclane , yes you are right. This involves a new resource called: Azure metric alert instead of the old alertrule resource. And we are currently working that new resource now.

@JunyiYi JunyiYi self-assigned this Oct 3, 2018
@JunyiYi JunyiYi changed the title I want to create an azurerm_metric_alertrule and use azurerm_monitor_action_group [New Resource] I want to create an Azure metric alert and use azurerm_monitor_action_group Oct 3, 2018
@JunyiYi JunyiYi added this to the Soon milestone Oct 3, 2018
@mmclane
Copy link
Author

mmclane commented Oct 3, 2018

cool

@tombuildsstuff tombuildsstuff changed the title [New Resource] I want to create an Azure metric alert and use azurerm_monitor_action_group New Resource: azurerm_monitor_action_group Oct 3, 2018
@JunyiYi JunyiYi changed the title New Resource: azurerm_monitor_action_group New Resource: azurerm_monitor_metric_alert Oct 3, 2018
@kkundank
Copy link

When I am trying to execute azurerm_monitor_metric_alert : It throws an error with Provider does not support this resource.. Could any one tell me please why this is happening ?

@JunyiYi
Copy link

JunyiYi commented Oct 18, 2018

Hi @mmclane @Kundan123456 , azurerm_monitor_metric_alert has been published just now in 1.17.0: https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alert.html. Please have a try and feel free to give us feedback.

@JunyiYi JunyiYi closed this as completed Oct 18, 2018
@kkundank
Copy link

Hi @JunyiYi , now its working fine. Thanks for information.

One more thing, how to create multiple unique alerts with different dimensions in same template ? Just by copy and pasting same thing again and changing the dimension or do we have any shortcuts here ?

Anyone can share their ideas. Thanks.

@tombuildsstuff tombuildsstuff modified the milestones: Soon, Being Sorted Oct 25, 2018
@baladevops
Copy link

baladevops commented Dec 19, 2018

Hi @JunyiYi , now its working fine. Thanks for information.

One more thing, how to create multiple unique alerts with different dimensions in same template ? Just by copy and pasting same thing again and changing the dimension or do we have any shortcuts here ?

Anyone can share their ideas. Thanks.

Can anyone update above query...I am having same requirement, how to create multiple unique alerts with different Operators....in terraform Criteria... thanks.
This is the one Im trying read, write, delete Networksecuritygroup rule for Azure...
criteria {
resource_id = "${azurerm_network_security_group.to_monitor.id}"
operation_name = "Microsoft.Network/networkSecurityGroups/securityRules/read"
category = "Administrative"
resource_type = "Microsoft.Network/networkSecurityGroups/securityRules"
}

criteria {
resource_id = "${azurerm_network_security_group.to_monitor.id}"
operation_name = "Microsoft.Network/networkSecurityGroups/securityRules/write"
category = "Administrative"
resource_type = "Microsoft.Network/networkSecurityGroups/securityRules"
}


output ERROR :

terraform plan

Error: azurerm_monitor_activity_log_alert.main: criteria: attribute supports 1 item maximum, config has 2 declared

@baladevops
Copy link

@JunyiYi @tombuildsstuff - Could you please suggest a solution for above my requirement. thanks

@tombuildsstuff
Copy link
Contributor

@baladevops you should be able to use a * to signify multiple sources such as Microsoft.Network/networkSecurityGroups/securityRules/*


Since the most recent comments are unrelated to the original issue I'm going to lock this issue for the moment.

@hashicorp hashicorp locked as off-topic and limited conversation to collaborators Dec 20, 2018
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