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

Win*_*oss 6 json azure dsc azure-resource-manager

我希望能够部署一个复杂的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')]",
              ...
                }
              }
            }
          }
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

Pas*_*ber 7

在Visual Studio中的"Azure资源组"项目中执行以下操作:

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

    更改azuredeploy.json:将参数assetLocation的名称更改为_artifactsLocation.

    第二步:添加参数_artifactsLocationSasToken作为securestring.这两个参数将由Visual Studio中的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"
      }
    },
Run Code Online (Sandbox Code Playgroud)
  1. 因为原始的azuredeploy.json没有使用_artifactsLocationSasToken参数.您需要更改使用assetlocation的所有变量.更改所有变量,使其使用_artifactsLocation并添加部件以使用_artifactsLocationSasToken.

一个样本:

"vnetTemplateUri": "[concat(parameters('_artifactsLocation'),'/nestedtemplates/vnet.json', parameters('_artifactsLocationSasToken'))]",
Run Code Online (Sandbox Code Playgroud)

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