使用 Azure Stack Hub 中的範本驗證工具Use the template validation tool in Azure Stack Hub

使用範本驗證工具,檢查您的 Azure Resource Manager 範本是否準備好部署至 Azure Stack Hub。Use the template validation tool to check whether your Azure Resource Manager templates are ready to deploy to Azure Stack Hub. 範本驗證工具可在 Azure Stack Hub tools GitHub 存放庫中取得。The template validation tool is available in the Azure Stack Hub tools GitHub repo. 使用從 GitHub 下載工具中所述的步驟下載 Azure Stack Hub 工具。Download the Azure Stack Hub tools by using the steps described in Download tools from GitHub.

概觀Overview

若要驗證範本,您必須先建置雲端功能檔案,然後執行驗證工具。To validate a template, you must first build a cloud capabilities file, and then run the validation tool. 使用 Azure Stack Hub 工具中的下列 PowerShell 模組:Use the following PowerShell modules from Azure Stack Hub tools:

  • azurerm.cloudcapabilities 資料夾中: Az. azurerm.cloudcapabilities. .psm1 建立一個代表 Azure Stack Hub 雲端中的服務和版本的雲端功能 JSON 檔案。In the CloudCapabilities folder: Az.CloudCapabilities.psm1 creates a cloud capabilities JSON file representing the services and versions in an Azure Stack Hub cloud.
  • azurerm.templatevalidator.psm1 資料夾中: Az. azurerm.templatevalidator.psm1. .psm1 使用雲端功能 JSON 檔案來測試範本,以在 Azure Stack Hub 中部署。In the TemplateValidator folder: Az.TemplateValidator.psm1 uses a cloud capabilities JSON file to test templates for deployment in Azure Stack Hub.

建置雲端功能檔案Build the cloud capabilities file

使用範本驗證程式之前,請先執行 Azurerm.cloudcapabilities PowerShell 模組來建立 JSON 檔案。Before you use the template validator, run the Az.CloudCapabilities PowerShell module to build a JSON file.

注意

如果您更新您的整合式系統,或新增任何新的服務或虛擬擴充功能,則應該再次執行此模組。If you update your integrated system, or add any new services or virtual extensions, you should run this module again.

  1. 確定您能順利連線到 Azure Stack Hub。Make sure you have connectivity to Azure Stack Hub. 這些步驟可從 Azure Stack 開發套件 (ASDK) 主機執行,或者您可以使用 VPN 從您的工作站連線。These steps can be done from the Azure Stack Development Kit (ASDK) host, or you can use a VPN to connect from your workstation.

  2. 匯入 Azurerm.cloudcapabilities PowerShell 模組:Import the Az.CloudCapabilities PowerShell module:

    Import-Module .\CloudCapabilities\Az.CloudCapabilities.psm1
    
  3. 使用 Get-CloudCapabilities Cmdlet 來擷取服務版本並建立雲端功能 JSON 檔案。Use the Get-CloudCapabilities cmdlet to retrieve service versions and create a cloud capabilities JSON file. 若未指定 -OutputPath,則會在目前的目錄中建立 AzureCloudCapabilities.json 檔案。If you do not specify -OutputPath, the file AzureCloudCapabilities.json is created in the current directory. 使用您的實際 Azure 位置:Use your actual Azure location:

Get-AzCloudCapability -Location <your location> -Verbose

驗證範本Validate templates

您可以使用下列步驟,使用 Az. Azurerm.templatevalidator.psm1 PowerShell 模組來驗證範本。Use these steps to validate templates by using the Az.TemplateValidator PowerShell module. 您可以使用您自己的範本,或使用 Azure Stack Hub 快速入門範本You can use your own templates, or use the Azure Stack Hub Quickstart templates.

  1. 匯入 Az. azurerm.templatevalidator.psm1. .Psm1 PowerShell 模組:Import the Az.TemplateValidator.psm1 PowerShell module:

    cd "c:\AzureStack-Tools-az\TemplateValidator"
    Import-Module .\Az.TemplateValidator.psm1
    
  2. 執行範本驗證程式:Run the template validator:

Test-AzTemplate -TemplatePath <path to template.json or template folder> `
-CapabilitiesPath <path to cloudcapabilities.json> `
-Verbose

範本驗證警告或錯誤會顯示在 PowerShell 主控台中,並寫入來源目錄中的 HTML 檔案。Template validation warnings or errors are displayed in the PowerShell console and written to an HTML file in the source directory. 下列螢幕擷取畫面是驗證報告的範例:The following screenshot is an example of a validation report:

範本驗證報告

參數Parameters

範本驗證程式 Cmdlet 支援下列參數。The template validator cmdlet supports the following parameters.

參數Parameter 描述Description 必要Required
TemplatePath 指定要在其中遞迴尋找 Azure Resource Manager 範本的路徑。Specifies the path to recursively find Azure Resource Manager templates. Yes
TemplatePattern 指定要比對的範本檔案名稱。Specifies the name of template files to match. No
CapabilitiesPath 指定雲端功能 JSON 檔案的路徑。Specifies the path to the cloud capabilities JSON file. Yes
IncludeComputeCapabilities 包括 IaaS 資源 (例如 VM 大小與 VM 擴充功能) 的評估。Includes evaluation of IaaS resources, such as VM sizes and VM extensions. No
IncludeStorageCapabilities 包括儲存體資源 (例如 SKU 類型) 的評估。Includes evaluation of storage resources, such as SKU types. No
Report 指定所產生之 HTML 報告的名稱。Specifies the name of the generated HTML report. No
Verbose 將錯誤與警告記錄到主控台。Logs errors and warnings to the console. No

範例Examples

這個範例會驗證已下載到本機儲存體的所有 Azure Stack Hub 快速入門範本This example validates all of the Azure Stack Hub Quickstart templates downloaded to local storage. 此範例也會針對 ASDK 功能,驗證虛擬機器 (VM) 大小和延伸模組。The example also validates virtual machine (VM) sizes and extensions against ASDK capabilities.

test-AzTemplate -TemplatePath C:\AzureStack-Quickstart-Templates `
-CapabilitiesPath .\TemplateValidator\AzureStackCloudCapabilities_with_AddOns_20170627.json `
-TemplatePattern MyStandardTemplateName.json `
-IncludeComputeCapabilities `
-Report TemplateReport.html

後續步驟Next steps