Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would like to be able to deploy a complex ARM template that utilizes DSC extensions and nested templates from my local Visual Studio. The example is set to download assets from GitHub: https://github.com/Azure/azure-quickstart-templates/tree/master/active-directory-new-domain-ha-2-dc What changes do I have to make that I can tie the assets to my local Visual Studio project and use them instead of downloading them from GitHub? Here is the strip down version of the template responsible for downloading:

{
  "$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')]",
              ...
                }
              }
            }
          }
        }
      ]
    }
  ]
}
like image 852
WinBoss Avatar asked Feb 05 '17 13:02

WinBoss


People also ask

Can we deploy the resources in parallel with ARM templates?

When resources aren't dependent on each other, Resource Manager deploys them in parallel. You only need to define dependencies for resources that are deployed in the same template. We recommend Bicep because it offers the same capabilities as ARM templates and the syntax is easier to use.

How will you use an ARM templates for deploying resources in Azure portal?

In a web browser, go to the Azure portal and sign in. From the Azure portal search bar, search for deploy a custom template and then select it from the available options. For Template source, notice that Quickstart template is selected by default. You can keep this selection.


1 Answers

Do the following in your 'Azure Resource Group' project in Visual Studio:

  1. Copy the files to your project in Visual Studio using the same directory structure. So a DSC directory and a nestedtemplates directory with the files that belong there.
  2. Set the files in the directories as content (azuredeploy.json is not needed, only the files you are referring to). This way the powershell script to deploy the templates will upload it to a storage account in azure.
  3. Make it possible to use files uploaded to the storage account. In this case the template that you are referring to is not using the common namingconvention. So you need to change it a bit:

    Change azuredeploy.json: Change the name of parameter assetLocation to _artifactsLocation.

    Second: Add a parameter _artifactsLocationSasToken as securestring. These 2 parameters will be filled automatically by the powershell script in Visual Studio.

part of the 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. Because the original azuredeploy.json is not using the _artifactsLocationSasToken parameter. You need to change all variables where the assetlocation is used. Change all variables so it uses the _artifactsLocation and add a part to use the _artifactsLocationSasToken.

one sample:

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

After you changed all variables. You can deploy the template from Visual Studio using the resources in your project instead of from github.

like image 56
Pascal Naber Avatar answered Oct 10 '22 17:10

Pascal Naber