下列範例會使用 Microsoft.OperationalInsights 工作區,在 Azure 監視器中建立 Log Analytics 工作區。 如需 Bicep 的詳細資訊,請參閱 Bicep 概觀。
Bicep 檔案
@description('Name of the workspace.')
param workspaceName string
@description('Pricing tier: PerGB2018 or legacy tiers (Free, Standalone, PerNode, Standard or Premium) which are not available to all customers.')
@allowed([
'pergb2018'
'Free'
'Standalone'
'PerNode'
'Standard'
'Premium'
])
param sku string = 'pergb2018'
@description('Specifies the location for the workspace.')
param location string
@description('Number of days to retain data.')
param retentionInDays int = 120
@description('true to use resource or workspace permissions. false to require workspace permissions.')
param resourcePermissions bool
@description('Number of days to retain data in Heartbeat table.')
param heartbeatTableRetention int
resource workspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
name: workspaceName
location: location
properties: {
sku: {
name: sku
}
retentionInDays: retentionInDays
features: {
enableLogAccessUsingOnlyResourcePermissions: resourcePermissions
}
}
}
resource workspaceName_Heartbeat 'Microsoft.OperationalInsights/workspaces/tables@2022-10-01' = {
parent: workspace
name: 'Heartbeat'
properties: {
retentionInDays: heartbeatTableRetention
}
}
注意
如果您指定免費定價層,請移除 retentionInDays 元素。
參數檔案
using './main.bicep'
param workspaceName = 'MyWorkspace'
param sku = 'pergb2018'
param location = 'eastus'
param retentionInDays = 120
param resourcePermissions = true
param heartbeatTableRetention = 30
下列範例會使用 Microsoft.OperationalInsights 工作區範本,在 Azure 監視器中建立 Log Analytics 工作區。
如需 Azure Resource Manager 範本的詳細資訊,請參閱 Azure Resource Manager 範本。
範本檔案
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
"metadata": {
"description": "Name of the workspace."
}
},
"sku": {
"type": "string",
"defaultValue": "pergb2018",
"allowedValues": [
"pergb2018",
"Free",
"Standalone",
"PerNode",
"Standard",
"Premium"
],
"metadata": {
"description": "Pricing tier: PerGB2018 or legacy tiers (Free, Standalone, PerNode, Standard or Premium) which are not available to all customers."
}
},
"location": {
"type": "string",
"metadata": {
"description": "Specifies the location for the workspace."
}
},
"retentionInDays": {
"type": "int",
"defaultValue": 120,
"metadata": {
"description": "Number of days to retain data."
}
},
"resourcePermissions": {
"type": "bool",
"metadata": {
"description": "true to use resource or workspace permissions. false to require workspace permissions."
}
},
"heartbeatTableRetention": {
"type": "int",
"metadata": {
"description": "Number of days to retain data in Heartbeat table."
}
}
},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2023-09-01",
"name": "[parameters('workspaceName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "[parameters('sku')]"
},
"retentionInDays": "[parameters('retentionInDays')]",
"features": {
"enableLogAccessUsingOnlyResourcePermissions": "[parameters('resourcePermissions')]"
}
}
},
{
"type": "Microsoft.OperationalInsights/workspaces/tables",
"apiVersion": "2022-10-01",
"name": "[format('{0}/{1}', parameters('workspaceName'), 'Heartbeat')]",
"properties": {
"retentionInDays": "[parameters('heartbeatTableRetention')]"
},
"dependsOn": [
"workspace"
]
}
]
}
注意
如果您指定免費定價層,請移除 retentionInDays 元素。
參數檔案
{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"value": "MyWorkspace"
},
"sku": {
"value": "pergb2018"
},
"location": {
"value": "eastus"
},
"resourcePermissions": {
"value": true
},
"heartbeatTableRetention": {
"value": 30
}
}
}