빠른 시작: Bicep 파일을 사용하여 Azure Network Watcher NSG 흐름 로그 구성

이 빠른 시작에서는 Bicep 파일을 사용하여 NSG 흐름 로그를 사용하도록 설정하는 방법을 알아봅니다.

Bicep은 선언적 구문을 사용하여 Azure 리소스를 배포하는 DSL(도메인 특정 언어)입니다. 간결한 구문, 신뢰할 수 있는 형식 안전성 및 코드 다시 사용에 대한 지원을 제공합니다. Bicep은 Azure에서 코드형 인프라 솔루션에 대한 최고의 제작 환경을 제공합니다.

필수 조건

Bicep 파일 검토

이 빠른 시작에서는 Azure 빠른 시작 템플릿에서 NSG 흐름 로그 만들기 Bicep 템플릿을 사용합니다.

@description('Name of the Network Watcher attached to your subscription. Format: NetworkWatcher_<region_name>')
param networkWatcherName string = 'NetworkWatcher_${location}'

@description('Name of your Flow log resource')
param flowLogName string = 'FlowLog1'

@description('Region where you resources are located')
param location string = resourceGroup().location

@description('Resource ID of the target NSG')
param existingNSG string

@description('Retention period in days. Default is zero which stands for permanent retention. Can be any Integer from 0 to 365')
@minValue(0)
@maxValue(365)
param retentionDays int = 0

@description('FlowLogs Version. Correct values are 1 or 2 (default)')
@allowed([
  1
  2
])
param flowLogsVersion int = 2

@description('Storage Account type')
@allowed([
  'Standard_LRS'
  'Standard_GRS'
  'Standard_ZRS'
])
param storageAccountType string = 'Standard_LRS'

var storageAccountName = 'flowlogs${uniqueString(resourceGroup().id)}'

resource storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: storageAccountType
  }
  kind: 'StorageV2'
  properties: {}
}

resource networkWatcher 'Microsoft.Network/networkWatchers@2022-01-01' = {
  name: networkWatcherName
  location: location
  properties: {}
}

resource flowLog 'Microsoft.Network/networkWatchers/flowLogs@2022-01-01' = {
  name: '${networkWatcherName}/${flowLogName}'
  location: location
  properties: {
    targetResourceId: existingNSG
    storageId: storageAccount.id
    enabled: true
    retentionPolicy: {
      days: retentionDays
      enabled: true
    }
    format: {
      type: 'JSON'
      version: flowLogsVersion
    }
  }
}

다음 리소스는 Bicep 파일에 정의되어 있습니다.

앞의 샘플에서 강조 표시된 코드는 NSG 흐름 로그 리소스 정의를 보여 줍니다.

Bicep 파일 배포

이 빠른 시작에서는 흐름 로그온을 사용하도록 설정할 수 있는 네트워크 보안 그룹이 있다고 가정합니다.

  1. Bicep 파일을 main.bicep으로 로컬 컴퓨터에 저장합니다.

  2. Azure CLI 또는 Azure PowerShell을 사용하여 Bicep 파일을 배포합니다.

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep
    

    기존 네트워크 보안 그룹의 리소스 ID를 입력하라는 메시지가 표시됩니다. 네트워크 보안 그룹 리소스 ID의 구문은 다음과 같습니다.

    "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/networkSecurityGroups/<network-security-group-name>"
    

배포가 완료되면 배포에 성공했음을 나타내는 메시지가 표시됩니다.

배포 유효성 검사

배포가 성공했는지 확인하는 두 가지 방법이 있습니다.

배포에 문제가 있는 경우 Azure Resource Manager를 사용한 일반적인 Azure 배포 오류 해결을 참조하세요.

리소스 정리

전체 배포 모드를 사용하여 Azure 리소스를 삭제할 수 있습니다. 흐름 로그 리소스를 삭제하려면 삭제하려는 리소스를 포함하지 않고 배포를 전체 모드로 지정합니다. 전체 배포 모드에 대해 읽어보세요.

Azure Portal에서 다음과 같이 NSG 흐름 로그를 사용하지 않도록 설정할 수도 있습니다.

  1. Azure Portal에 로그인합니다.

  2. 포털 맨 위에 있는 검색 상자에 Network Watcher를 입력합니다. 검색 결과에서 Network Watcher를 선택합니다.

  3. 로그에서 흐름 로그를 선택합니다.

  4. 흐름 로그 목록에서 사용하지 않도록 설정할 흐름 로그를 선택합니다.

  5. 사용 안 함을 선택합니다.

NSG 흐름 로그 데이터를 시각화하는 방법을 알아보려면 다음을 참조하세요.