DeMaki
DeMaki

Reputation: 491

How to configure Daily Cap on Application Insights in ARM or bicep?

I created a new Log Analytics Workspace in the Azure Portal and manually set a Daily Cap of 5 GB/day. Next I created a new Application Insights resource in the Azure Portal which links to the newly created Log Analytics Workspace. I notice in the portal I can set a Daily Cap on the Application Insights resource as well, let's set it for the sake of it to 2 GB/day.

Then I try to export the ARM template and notice I get 4 errors:

{
  "code": "ExportTemplateCompletedWithErrors",
  "message": "Export template operation completed with errors. Some resources were not exported. Please see details for more information.",
  "details": [
    {
      "code": "ExportTemplateProviderError",
      "target": "Microsoft.Insights/components/Annotations",
      "message": "Could not get resources of the type 'Microsoft.Insights/components/Annotations'. Resources of this type will not be exported."
    },
    {
      "code": "ExportTemplateProviderError",
      "target": "microsoft.insights/components/pricingPlans",
      "message": "Could not get resources of the type 'microsoft.insights/components/pricingPlans'. Resources of this type will not be exported."
    },
    {
      "code": "ExportTemplateProviderError",
      "target": "microsoft.insights/components/myanalyticsItems",
      "message": "Could not get resources of the type 'microsoft.insights/components/myanalyticsItems'. Resources of this type will not be exported."
    },
    {
      "code": "ExportTemplateProviderError",
      "target": "Microsoft.Insights/components/currentbillingfeatures",
      "message": "Could not get resources of the type 'Microsoft.Insights/components/currentbillingfeatures'. Resources of this type will not be exported."
    }
  ]
}

The generated template does not include any details on the Daily Cap. I guess it should have been part of the currentbillingfeatures. In the bicep template I also do not see anything related to Daily Cap (see https://learn.microsoft.com/en-us/azure/templates/microsoft.insights/components?pivots=deployment-language-bicep).

How can I set the Daily Cap on Application Insights using bicep?

Upvotes: 0

Views: 781

Answers (1)

Jahnavi
Jahnavi

Reputation: 7898

To achieve your requirement using bicep, you need to use Microsoft. Insights/components/pricingPlans resource because Microsoft.insights/components/CurrentBillingFeatures is not supported in bicep anymore. If ARM template works for your environment, then you can proceed with the current billing features insights resource as you used.

Reference ARM template to configure the Daily cap using billing features resource.

And coming to your requirement, use pricing plan resource as explained above, I was able to deploy it successfully without any issues.

  1. Created a log analytics resource as well as an application insights component as shown below using bicep.
param resourceworkspace string = 'newtodayws'
param location string = resourceGroup().location
param appsight string = 'newtodaysight'
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
  name: resourceworkspace
  location: location
  properties: {
    sku: {
      name: 'PerGB2018'
    }
    retentionInDays: 90
    workspaceCapping: {
      dailyQuotaGb: 5
    }
  }
}

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: appsight
  location: location
  kind: 'web'
  properties: {
    Application_Type: 'web'
    WorkspaceResourceId: logAnalytics.id
  }
}
  1. Once it is created, set up a daily volume cap limit using Microsoft.Insights/components/pricingPlans in bicep.
@description('Daily quota in GB.')
@minValue(1)
param dailyQuota int = 5
param warningThreshold int = 90
param appsight string = 'newtodaysight'

resource app 'Microsoft.Insights/components@2020-02-02' existing = {
  name: appsight
}

resource pricingplan 'Microsoft.Insights/components/pricingPlans@2017-10-01' = {
  name: 'current'
  parent: app
  properties: {
    cap: dailyQuota
    planType: 'Basic'
    stopSendNotificationWhenHitCap: true
    warningThreshold: warningThreshold
    }
  }

Deployment succeeded:

enter image description here

enter image description here

Upvotes: 1

Related Questions