Recently I helped Rob Bos by creating an ARM template, that allowed him to spin up a VM in Azure and which would host a Chocolatey Server. Rob wrote a nice blog post about this. As he mentions in his post, there are still some issues with the ARM template. On major thing is fixed though: The DSC step no longer fails and it’s no longer necessary to manually execute PowerShell. Here’s how I fixed it.

Microsoft Azure

How to make PowershellDscExtension and CustomScriptExtension depend on each other in ARM

  1. Add the VM and both extensions to your ARM template and give them proper names.
  2. Create the dependsOn element at the CustomScriptExtension and follow the next steps to determine what to fill in here.
  3. Take the type and name of the VM your extensions will run on, in the example below that would be: “Microsoft.Compute/virtualMachines/ChocolateyServer”
  4. Add /extensions and then /name-of-the-extension-you-depend-on, so that would be: “Microsoft.Compute/virtualMachines/ChocolateyServer/extensions/NeverGonna”
  5. Enjoy your dependency! If you need any more help, have a look at the example below or reach out!

So the key thing is: you’re not depending on something by just it’s name, you’re depending on the (end of the) resource identifier. An easy way to find this identifier is by going to the Azure resource explorer, which gives you a nice view of all the resources in your subscriptions. Just add the DSC first, then check out the identifier and then add the script.

Something to watch out for is that my extensions were actually named: “ChocServ/PowershellDscExtension” and “ChocServ/CustomScriptExtension”. However, only the latter part was used in my resource identifiers. So in my dependsOn I needed to leave out the “ChocServ/” part. Again, have a look at the Azure resource explorer to find out the exact identifier.

It should look something like this

    {
      "type": "Microsoft.Compute/virtualMachines",
      "name": ChocolateyServer",
    },
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "NeverGonna",
      "dependsOn": [
        "Microsoft.Compute/virtualMachines/ChocolateyServer"
      ]
    },
    {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "GiveYouUp",
      "dependsOn": [
        "Microsoft.Compute/virtualMachines/ChocolateyServer/extensions/NeverGonna"
      ]
    }

Nice! So now I can have multiple scripts depending on each other?

Nope. One thing I learned while fixing my ARM template, is that you can’t have multiple PowershellDscExtension or multiple CustomScriptExtension in one ARM template. Not sure why. You can have a single one of both though. So if you came here looking how to execute multiple PowerShell scripts, you’re looking in the wrong place. There are ways to do that though and here’s a starting point.

Remaining issues in the Chocolatey Server ARM template

There are some small remaining issues with the ARM template, which you can see here. Feel free to submit a pull request or add new issues if you have any. I’ll try and fix them. You can also find the ChocolateyServer ARM template there.