1

I am trying to deploy multiple script to an Azure Windows VM by using Custom Script Extension. The scripts are independent from each other so the order of their deployment doesn't matter. But the scripts are in different in different storage accounts. I have already a working template as below:

{
   "properties":{
      "mode":"incremental",
      "parameters":{
         "vmList":{
            "value":"[field('name')]"
         },
         "vmLocation":{
            "value":"[field('location')]"
         }
      },
      "template":{
         "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
         "contentVersion":"1.0.0.0",
         "parameters":{
            "vmList":{
               "metadata":{
                  "description":""
               },
               "minLength":1,
               "type":"String"
            },
            "vmLocation":{
               "metadata":{
                  "description":""
               },
               "type":"String"
            }
         },
         "resources":[
            {
               "apiVersion":"2015-06-15",
               "copy":{
                  "count":"[length(variables('vmListArray'))]",
                  "name":"myAgent"
               },
               "location":"[parameters('vmLocation')]",
               "name":"[concat(trim(variables('vmListArray')[copyIndex()]),'/myAgent')]",
               "properties":{
                  "autoUpgradeMinorVersion":true,
                  "protectedSettings":{
                     "commandToExecute":"[concat ('powershell -ExecutionPolicy Unrestricted -File \"./scripts/installation-myagent.ps1\"')]",
                     "storageAccountKey":"here comes storage ac. key",
                     "storageAccountName":"mystorageaccount"
                  },
                  "publisher":"Microsoft.Compute",
                  "settings":{
                     "fileUris":"[split(variables('fileUris'), ' ')]"
                  },
                  "type":"CustomScriptExtension",
                  "typeHandlerVersion":"1.7"
               },
               "type":"Microsoft.Compute/virtualMachines/extensions"
            }
         ],
         "variables":{
            "fileUris":"https://mystorageaccount.blob.core.windows.net/scripts/installation-myagent.ps1",
            "vmListArray":"[split(parameters('vmList'),',')]"
         }
      }
   }
}

Because the protected settings of each script is different, i am not sure if this is possible at all. Do you have any idea?

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
MoonHorse
  • 1,966
  • 2
  • 24
  • 46

1 Answers1

0

This can be accomplished by having Custom Script Extension execute a wrapper script which accepts your secret parameters, then downloads your additional scripts from another source (such as an Azure Storage Account) and executes each script, passing the parameters provided in the CSE protected settings to the appropriate script.

Matthew
  • 579
  • 3
  • 6