Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Log Analytics Workspace key from Bicep

In a bicep file for an App Service, I want to grab the id and key from an existing Log Analytic Workbench, created in another repo/bicep file.

I see this is possible in Terraform, but cannot find any docs on how to achieve this with Bicep, which seems a bit odd.

What I thought should be possible would be something like this;

// Refer to existing Log Analytics Workbench
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' existing = {
  name: logAnalyticsWorkspaceName
}

and then doing something like;

logAnalyticsWorkspace.properties.keys.primary_shared_key

Any tips?

like image 824
objectclass Avatar asked Oct 18 '25 09:10

objectclass


1 Answers

you would need to use the listKeys function:


// Get a reference to the existing log analytics workspace
resource logAnalyticWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' existing = {
  name: logAnalyticWorkspaceName
}

var primaryKey = logAnalyticWorkspace.listKeys().primarySharedKey
like image 99
Thomas Avatar answered Oct 21 '25 21:10

Thomas