如何在Bicep模板中创建Azure网络安全组/NSG流日志?
我想为我用Bicep创建的网络安全组和存储帐户创建NSG流日志 我正在部署一个类似NSG的如何在Bicep模板中创建Azure网络安全组/NSG流日志?,azure,azure-resource-manager,azure-virtual-network,azure-bicep,Azure,Azure Resource Manager,Azure Virtual Network,Azure Bicep,我想为我用Bicep创建的网络安全组和存储帐户创建NSG流日志 我正在部署一个类似NSG的 resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = { name: networkSecurityGroupName location: location properties: { securityRules: [ ... 还有一个存储帐户,比如 resource stg 'Microsoft.St
resource nsg 'Microsoft.Network/networkSecurityGroups@2020-06-01' = {
name: networkSecurityGroupName
location: location
properties: {
securityRules: [
...
还有一个存储帐户,比如
resource stg 'Microsoft.Storage/storageAccounts@2021-01-01' = {
name: storageName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
但在添加和部署NSG流时
resource nsgFlowLogs 'Microsoft.Network/networkWatchers/flowLogs@2020-08-01' = {
name: 'NetworkWatcher_${location}/${nsgFlowName}'
location: location
properties: {
targetResourceId: nsg.Id
storageId: stg.Id
enabled: true
retentionPolicy: {
days: 2
enabled: true
}
format: {
type: 'JSON'
version: 2
}
}
}
我犯了一个错误
| 19:02:20 - Error: Code=ResourceCountExceedsLimitDueToTemplate; Message=Subscription
| 853049fd-4889-45b6-aad9-f3f54421399c has a quota of 1 for resources of type NetworkWatcher with sku SkuNotSpecified.
| Subscription currently has 1 resources and the template contains 1 new resources of the this type which exceeds the
| quota. Please contact support to increase the quota for resource type NetworkWatcher
我发现需要在预定义的资源组
NetworkWatcherRG
中创建网络观察者资源和相应的流日志
因此,我提取了一个模块nsgflowlog.bicep
param name string
param location string = resourceGroup().location
param nsgId string
param storageId string
resource nsgFlowLogs 'Microsoft.Network/networkWatchers/flowLogs@2020-08-01' = {
name: 'NetworkWatcher_${location}/${name}'
location: location
properties: {
targetResourceId: nsgId
storageId: storageId
enabled: true
retentionPolicy: {
days: 2
enabled: true
}
format: {
type: 'JSON'
version: 2
}
}
}
这样,我就可以在部署期间切换资源组:
module nsgFlow './nsgflowlog.bicep' = {
name: '${resourcePrefix}-nsgFlow'
scope: resourceGroup('NetworkWatcherRG')
params: {
name: nsgFlowName
nsgId: nsg.id
storageId: stg.id
}
}