3

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?

Thomas
  • 24,234
  • 6
  • 81
  • 125
objectclass
  • 154
  • 1
  • 3
  • 13
  • Maybe listKeys will work, something like logAnalyticsWorkspace.listKeys().keys[0].value . Typically that is how you get keys like that, I have used for storage account but not log analytics. More info here https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#list – Scott Mildenberger Oct 24 '22 at 15:21

1 Answers1

7

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
Thomas
  • 24,234
  • 6
  • 81
  • 125
  • Will this work safely if your workspace is in a module? I'm trying to get the output of the key from the module and this is not advised as outputs are not safe. – The Senator Nov 10 '22 at 18:02
  • I now get a warning when using `listKeys(...)` saying I should use `a resource reference` instead. – Marti Nito Apr 03 '23 at 13:23