Home > Net >  Error creating azurerm_monitor_metric_alert for ServiceBus on Azure with Terraform
Error creating azurerm_monitor_metric_alert for ServiceBus on Azure with Terraform

Time:12-10

I'm unable to create an azurerm_monitor_metric_alert. I'd need it to monitor the Deadlettered Messages of a Service Bus. I'm using Terraform 1.0.11 on Linux and azurerm v2.88.1.

The error I'm getting is this:

azurerm_monitor_metric_alert.sb_dlq_example: Creating...

Error: creating or updating Monitor Metric Alert: (Name "DLQ Alert owashoh" / Resource Group "SharedienDevelopment"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ResourceNotFound" Message="{\"code\":\"BadRequest\",\"message\":\"Detect invalid value: Microsoft.ServiceBus/namespaces for query parameter: 'metricnamespace', the value must be: Microsoft.ServiceBus/namespaces/queues if the query parameter is provided, you can also skip this optional query parameter.\"} Activity ID: 1cc2c166-ffaf-4fbc-bd07-bc49b04e9f1e."

  with azurerm_monitor_metric_alert.sb_dlq_example,
  on service_bus.tf line 118, in resource "azurerm_monitor_metric_alert" "sb_dlq_example":
 118: resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

Detect invalid value: Microsoft.ServiceBus/namespaces for query parameter: 'metricnamespace', the value must be: Microsoft.ServiceBus/namespaces/queues

data "azurerm_resource_group" "this" {
  name = "Example"
}

resource "azurerm_monitor_action_group" "example" {
  name                = "Error Alerts Action owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  short_name          = "p4action"

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

resource "azurerm_servicebus_namespace" "example" {
  name                = "tfex-servicebus-namespace-owashoh"
  location            = data.azurerm_resource_group.this.location
  resource_group_name = data.azurerm_resource_group.this.name
  sku                 = "Standard"
}

resource "azurerm_servicebus_queue" "example" {
  name                = "tfex_servicebus_queue_owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  namespace_name      = azurerm_servicebus_namespace.example.name
  enable_partitioning = true
}

resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

  scopes = [ azurerm_servicebus_queue.example.id ]

  name                = "DLQ Alert owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  description         = "DLQ Alert."
  severity            = 4

  criteria {
    metric_namespace = "Microsoft.ServiceBus/namespaces" #### <====

    metric_name = "DeadletteredMessages"
    aggregation = "Average"
    operator    = "GreaterThanOrEqual"
    threshold   = 5
  }

  action {
    action_group_id    = azurerm_monitor_action_group.example.id
  }
}

The error is in the marked line: metric_namespace = "Microsoft.ServiceBus/namespaces"

I replaced this with metric_namespace = "Microsoft.ServiceBus/namespaces/queues", but it still fails. Error:

Error: creating or updating Monitor Metric Alert: (Name "DLQ Alert owashoh" / Resource Group "SharedienDevelopment"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ResourceNotFound" Message="{\"code\":\"BadRequest\",\"message\":\"Microsoft.ServiceBus/namespaces/queues is not a supported platform metric namespace, supported ones are Microsoft.AnalysisServices/servers,Microsoft.Web/staticSites,Microsoft.Web/serverFarms,Microsoft.Web/sites,Microsoft.Web/sites/slots,Microsoft.Web/hostingEnvironments,Microsoft.Web/hostingEnvironments/multiRolePools,Microsoft.Web/hostingEnvironments/workerPools,Microsoft.Web/connections,Microsoft.IoTCentral/IoTApps,Microsoft.ServiceBus/namespaces,Microsoft.HealthcareApis/services,Microsoft.HealthcareApis/workspaces/iotconnectors,Microsoft.Network/virtualNetworks,Microsoft.Network/natGateways,Microsoft.Network/publicIPAddresses,Microsoft.Network/networkInterfaces,Microsoft.Network/privateEndpoints,Microsoft.Network/loadBalancers,Microsoft.Network/networkWatchers/connectionMonitors,Microsoft.Network/virtualNetworkGateways,Microsoft.Network/connections,Microsoft.Network/applicationGateways,Microsoft.Network/dnszones,Microsoft.Network/privateDnsZones,Microsoft.Network/trafficmanagerprofiles,Microsoft.Network/expressRouteCircuits,Microsoft.Network/vpnGateways,Microsoft.Network/p2sVpnGateways,Microsoft.Network/expressRouteGateways,Microsoft.Network/expressRoutePorts,Microsoft.Network/azureFirewalls,Microsoft.Network/privateLinkServices,Microsoft.Network/frontdoors,Microsoft.Network/virtualRouters,Microsoft.DBforMySQL/servers,Microsoft.DBforMySQL/flexibleServers,microsoft.insights/components,microsoft.insights/autoscalesettings,Microsoft.Sql/servers,Microsoft.Sql/servers/databases,Microsoft.Sql/servers/elasticpools,Microsoft.Sql/managedInstances,Microsoft.KeyVault/vaults,Microsoft.Cache/Redis,Microsoft.Cache/redisEnterprise,Microsoft.ContainerRegistry/registries,Microsoft.DocumentDB/databaseAccounts,Microsoft.VMwareCloudSimple/virtualMachines,Microsoft.ContainerInstance/containerGroups,Microsoft.Devices/IotHubs,Microsoft.Devices/ElasticPools,Microsoft.Devices/ElasticPools/IotHubTenants,Microsoft.Devices/ProvisioningServices,Microsoft.Compute/virtualMachines,Microsoft.Compute/virtualMachineScaleSets,Microsoft.Compute/virtualMachineScaleSets/virtualMachines,Microsoft.Compute/cloudServices,Microsoft.Compute/cloudServices/roles,Microsoft.Synapse/workspaces,Microsoft.Synapse/workspaces/bigDataPools,Microsoft.Synapse/workspaces/sqlPools,Microsoft.Synapse/workspaces/kustoPools,Microsoft.ClassicCompute/domainNames/slots/roles,Microsoft.ClassicCompute/virtualMachines,Microsoft.SignalRService/SignalR,Microsoft.SignalRService/WebPubSub,Microsoft.DataBoxEdge/DataBoxEdgeDevices,Microsoft.StorageCache/caches,Microsoft.Search/searchServices,Microsoft.Logic/workflows,Microsoft.Logic/integrationServiceEnvironments,Microsoft.HDInsight/clusters,Microsoft.MachineLearningServices/workspaces,Microsoft.DataCollaboration/workspaces,Microsoft.Purview/accounts,Microsoft.Relay/namespaces,Microsoft.DigitalTwins/digitalTwinsInstances,Microsoft.EventHub/namespaces,Microsoft.EventHub/clusters,Microsoft.Kusto/clusters,Microsoft.OperationalInsights/workspaces,Microsoft.Maps/accounts,Microsoft.DBforMariaDB/servers,Microsoft.TimeSeriesInsights/environments,Microsoft.TimeSeriesInsights/environments/eventsources,Microsoft.AppPlatform/Spring,Microsoft.DBforPostgreSQL/servers,Microsoft.DBforPostgreSQL/serversv2,Microsoft.DBforPostgreSQL/singleServers,Microsoft.DBforPostgreSQL/flexibleServers,Microsoft.StreamAnalytics/streamingjobs,Microsoft.Cdn/profiles,Microsoft.Cdn/CdnWebApplicationFirewallPolicies,Microsoft.AVS/privateClouds,Microsoft.NotificationHubs/namespaces/notificationHubs,Microsoft.ApiManagement/service,Microsoft.Storage/storageAccounts,Microsoft.Storage/storageAccounts/blobServices,Microsoft.Storage/storageAccounts/tableServices,Microsoft.Storage/storageAccounts/queueServices,Microsoft.Storage/storageAccounts/fileServices,Microsoft.Media/mediaservices,Microsoft.Media/mediaservices/streamingEndpoints,Microsoft.Media/mediaservices/liveEvents,Microsoft.DataLakeAnalytics/accounts,Microsoft.ServiceFabricMesh/applications,Microsoft.PowerBIDedicated/capacities,Microsoft.ClassicStorage/storageAccounts,Microsoft.ClassicStorage/storageAccounts/blobServices,Microsoft.ClassicStorage/storageAccounts/tableServices,Microsoft.ClassicStorage/storageAccounts/fileServices,Microsoft.ClassicStorage/storageAccounts/queueServices,microsoft.aadiam/azureADMetrics,Microsoft.AppConfiguration/configurationStores,Microsoft.Automation/automationAccounts,Microsoft.DataLakeStore/accounts,Microsoft.DataFactory/dataFactories,Microsoft.DataFactory/factories,Microsoft.NetApp/netAppAccounts/capacityPools,Microsoft.NetApp/netAppAccounts/capacityPools/volumes,Microsoft.DataShare/accounts,Microsoft.Peering/peerings,Microsoft.Peering/peeringServices,Microsoft.StorageSync/storageSyncServices,Microsoft.MixedReality/spatialAnchorsAccounts,Microsoft.MixedReality/remoteRenderingAccounts,Microsoft.ContainerService/managedClusters,Microsoft.Blockchain/blockchainMembers,Microsoft.Batch/batchAccounts,Microsoft.EventGrid/eventSubscriptions,Microsoft.EventGrid/topics,Microsoft.EventGrid/domains,Microsoft.EventGrid/extensionTopics,Microsoft.EventGrid/systemTopics,Microsoft.EventGrid/partnerNamespaces,Microsoft.EventGrid/partnerTopics,Microsoft.CognitiveServices/accounts,Microsoft.Media/videoanalyzers,Microsoft.MachineLearningServices/workspaces/onlineEndpoints,Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments,microsoft.keyvault/managedhsms,microsoft.network/vpngateways,microsoft.network/bastionHosts,Microsoft.Network/applicationgateways,microsoft.network/virtualnetworkgateways,Microsoft.Network/virtualHubs,microsoft.network/p2svpngateways,Microsoft.Cloudtest/pools,Microsoft.Cloudtest/hostedpools,microsoft.avs/privateClouds,microsoft.compute/disks,Microsoft.Compute/virtualmachineScaleSets,Microsoft.Logic/IntegrationServiceEnvironments,Microsoft.Logic/Workflows,Microsoft.Cdn/cdnwebapplicationfirewallpolicies,Microsoft.DocumentDB/cassandraClusters,Microsoft.DocumentDB/DatabaseAccounts,Wandisco.Fusion/migrators/liveDataMigrations,Wandisco.Fusion/migrators/metadataMigrations,Wandisco.Fusion/migrators,Microsoft.ConnectedVehicle/platformAccounts,Microsoft.Communication/CommunicationServices,microsoft.hybridnetwork/networkfunctions,microsoft.purview/accounts,Microsoft.Cache/redis,microsoft.kubernetes/connectedClusters,Microsoft.DBForPostgreSQL/serverGroupsv2,Microsoft.RecoveryServices/Vaults. TraceId: {996569c7-cdfe-429c-ba2f-86bba2b1cfb1}\"} Activity ID: 5694bf32-c589-4587-8cb1-1b80f7a571ea."

  with azurerm_monitor_metric_alert.sb_dlq_example,
  on service_bus.tf line 118, in resource "azurerm_monitor_metric_alert" "sb_dlq_example":
 118: resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

⸘Well…‽ How do you create such an alert?

CodePudding user response:

Your code seems fine except for the scope parameter in the Metric Alert resource block. You should use scopes =[azurerm_servicebus_namespace.example.id] instead of scopes = [azurerm_servicebus_queue.example.id ] as deadletteredmessages is available for Namespaces which will monitor average count of dead-lettered messages for queue/topic present inside a namespace and also as the Metric_Namespace is enter image description here

enter image description here

  • Related