Linter 規則 - 使用穩定的 VM 映像

虛擬機器不得使用預覽映像。 此規則會檢查 "imageReference" 下的下列屬性,若其中任何屬性包含字串 "preview" 則會失敗:

  • 供應項目
  • SKU
  • version

Linter 規則程式碼

使用 Bicep 設定檔中的下列值來自訂規則設定:

use-stable-vm-image

解決方案

下列範例會導致此測試失敗。

param location string = resourceGroup().location

resource vm 'Microsoft.Compute/virtualMachines@2023-03-01' = {
  name: 'virtualMachineName'
  location: location
  properties: {
    storageProfile: {
      imageReference: {
        offer: 'WindowsServer-preview'
        sku: '2019-Datacenter-preview'
        version: 'preview'
      }
    }
  }
}

您可在 imageReference 中使用不含字串 preview 的映像來修正此問題。

param location string = resourceGroup().location

resource vm 'Microsoft.Compute/virtualMachines@2023-03-01' = {
  name: 'virtualMachineName'
  location: location
  properties: {
    storageProfile: {
      imageReference: {
        offer: 'WindowsServer'
        sku: '2019-Datacenter'
        version: 'latest'
      }
    }
  }
}

下一步

如需 Linter 的詳細資訊,請參閱使用 Bicep Linter