次のサンプルでは、Microsoft.OperationalInsights ワークスペースを使用して、Azure Monitor に 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
}
}
Note
Free の価格レベルを指定する場合は、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 Monitor に 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"
]
}
]
}
Note
Free の価格レベルを指定する場合は、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
}
}
}