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

Modify azurerm_monitor_metric_alert for Microsoft.Sql/servers/databases fail #21589

Closed
1 task done
Jerico815 opened this issue Apr 27, 2023 · 2 comments · Fixed by #21658
Closed
1 task done

Modify azurerm_monitor_metric_alert for Microsoft.Sql/servers/databases fail #21589

Jerico815 opened this issue Apr 27, 2023 · 2 comments · Fixed by #21658
Labels

Comments

@Jerico815
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

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

Terraform Version

1.4.5

AzureRM Provider Version

3.53.0

Affected Resource(s)/Data Source(s)

azurerm_monitor_metric_alert

Terraform Configuration Files

resource "azurerm_monitor_metric_alert" "alert_sql_database_freediskspacepercent" {
  provider                 = azurerm.sub01
  count                    = local.sql_database_sub01 == [] ? 0 : 1
  enabled                  = local.all_alerts_enabled
  name                     = "SQL_Database_FreeDiskSpacePercent"
  description              = "xxx"
  resource_group_name      = azurerm_resource_group.this.name
  auto_mitigate            = true
  scopes                   = local.sql_database_sub01
  severity                 = 2
  tags                     = local.tags
  target_resource_location = local.location
  target_resource_type     = "Microsoft.Sql/servers/databases"
  window_size              = "PT15M"
  frequency                = "PT15M"

  action {
    action_group_id = local.action_groups[0]
  }

  criteria {
    aggregation            = "Maximum"
    metric_name            = "storage_percent"
    metric_namespace       = "Microsoft.Sql/servers/databases"
    operator               = "GreaterThan"
    skip_metric_validation = false
    threshold              = 80
  }
}


locals {
     sql_database_sub01 = [
"/subscriptions/xxxx/resourceGroups/rg01/providers/Microsoft.Sql/servers/sqlserver01/databases/db01",
"/subscriptions/xxxx/resourceGroups/rg02/providers/Microsoft.Sql/servers/sqlserver02/databases/db02",
"/subscriptions/xxxx/resourceGroups/rg03/providers/Microsoft.Sql/servers/sqlserver03/databases/db03",
"/subscriptions/xxxx/resourceGroups/rg04/providers/Microsoft.Sql/servers/sqlserver04/databases/db04",
"/subscriptions/xxxx/resourceGroups/rg05/providers/Microsoft.Sql/servers/sqlserver05/databases/db05"
]
}

Debug Output/Panic Output

Error: creating or updating Monitor Metric Alert (Subscription: "xxx"
│ Resource Group Name: "xxx"
│ Metric Alert Name: "SQL_Database_FreeDiskSpacePercent"): metricalerts.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Scopes property is invalid. Only single resource is allowed for criteria type SingleResourceMultipleMetricCriteria. If you want to create an alert on multiple resources, use MultipleResourceMultipleMetricCriteria odata.type."

Expected Behaviour

Modify alert

Actual Behaviour

Error see above

The strange thing is, if I create the alert from scratch as an example with 5 databases, everything is fine.
If I want to modify the existing alert (add or remove a single database), I get the error.
If I am using the Azure Portal, everything works fine.

Any ideas?

Steps to Reproduce

  1. terraform apply
  2. Everything is working
  3. Add or Remove ids from the local.sql_database_sub01 (local.sql_database_sub01 contains the database ids)
  4. terraform apply
  5. Error

Important Factoids

No response

References

No response

@davejdeemer
Copy link

davejdeemer commented May 4, 2023

For what it's worth, I just bumped in this today. I dropped down to 3.52.0, same error. On 3.51.0, for my use case the apply is successful.

Experienced the same as reported; initial build is fine on any of the 3 versions I've tried. The error happens with an update. In my case, I was adding an action.

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants