Azure RM 模板。如何使用 VS 自动上传资产而不是从 GitHub 中获取资产

Azure RM Templates. How to upload assets automatically with VS instead of fetching them from GitHub

我希望能够部署一个复杂的 ARM 模板,该模板利用本地 Visual Studio 中的 DSC 扩展和嵌套模板。 该示例设置为从 GitHub 下载资源: https://github.com/Azure/azure-quickstart-templates/tree/master/active-directory-new-domain-ha-2-dc 我必须进行哪些更改才能将资产绑定到我的本地 Visual Studio 项目并使用它们而不是从 GitHub 下载它们? 这是负责下载的模板的精简版:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    ...
    "adPDCVMName": {
      "type": "string",
      "metadata": {
        "description": "The computer name of the PDC"
      },
      "defaultValue": "adPDC"
    },
    "assetLocation": {
      "type": "string",
      "metadata": {
        "description": "The location of resources such as templates and DSC modules that the script is dependent"
      },
      "defaultValue": "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/active-directory-new-domain-ha-2-dc"
    }
    ...
  },
  "variables": {
    ...
    "adPDCModulesURL": "[concat(parameters('assetLocation'),'/DSC/CreateADPDC.ps1.zip')]",
    "adPDCConfigurationFunction": "CreateADPDC.ps1\CreateADPDC",
    ...
  },
  "resources": [
    ...
    {
      "name": "[parameters('adPDCVMName')]",
      "type": "Microsoft.Compute/virtualMachines",
      ...
      "resources": [
        {
          "name": "[concat(parameters('adPDCVMName'),'/CreateADForest')]",
          "type": "Microsoft.Compute/virtualMachines/extensions",
          ...
          "properties": {
          ...
            "settings": {
              "ModulesUrl": "[variables('adPDCModulesURL')]",
              "ConfigurationFunction": "[variables('adPDCConfigurationFunction')]",
              ...
                }
              }
            }
          }
        }
      ]
    }
  ]
}

在 Visual Studio 中的 'Azure Resource Group' 项目中执行以下操作:

  1. 使用相同的方法将文件复制到 Visual Studio 中的项目 目录结构。所以一个 DSC 目录和一个 nestedtemplates 目录 属于那里的文件。
  2. 将目录中的文件设置为内​​容(不需要azuredeploy.json,只需要您所指的文件)。这样,部署模板的 powershell 脚本会将其上传到 azure 中的存储帐户。
  3. 可以使用上传到存储帐户的文件。在这种情况下,您所指的模板没有使用通用的 命名约定。所以你需要稍微改变一下:

    更改azuredeploy.json:更改参数名称 assetLocation 到 _artifactsLocation。

    二:添加一个参数 _artifactsLocationSasToken 作为安全字符串。这 2 个参数将由 Visual Studio.

  4. 中的 powershell 脚本自动填充

azuredeploy.json的一部分:

"parameters": {
    "_artifactsLocation": {
      "type": "string",
      "metadata": {
        "description": "The base URI where artifacts required by this template are located. When the template is deployed using the accompanying scripts, a private location in the subscription will be used and this value will be automatically generated."
      }
    },
    "_artifactsLocationSasToken": {
      "type": "securestring",
      "metadata": {
        "description": "The SAS token to access the storage account"
      }
    },
  1. 因为原来的azuredeploy.json没有使用_artifactsLocationSasToken参数。您需要更改使用 assetlocation 的所有变量。更改所有变量,使其使用 _artifactsLocation 并添加一部分以使用 _artifactsLocationSasToken。

一个样本:

"vnetTemplateUri": "[concat(parameters('_artifactsLocation'),'/nestedtemplates/vnet.json', parameters('_artifactsLocationSasToken'))]",

更改所有变量后。您可以使用项目中的资源从 Visual Studio 部署模板,而不是从 github.