ARM JSON: Azure Virtual Machine Extension – Executing Script.

I wrote a blog on how to install IIS web server while you are installing Virtual Machine using either Terraform or ARM JSON, but that was for a single line command how about running the script using ARM JSON Virtual Machine Extension.

In this blog we will see how to run script using ARM JSON, if you want to learn how we execute virtual machine extension you should refer to some of the other blogs that i have written for Terraform and for Azure ARM templates.

Here are couple of links:

so once you have fair understanding on how to execute single command line from either Terraform or from Azure ARM templates we can take it step further.

Other then couple of arguments everything else will remain as it, as you can see if you want to execute PowerShell script you should be uploading them somewhere online, either in storage account or in github (raw form).

The “install-webserver.ps1” will be picked up from storage account and handed over to section “commandToExecute” where PowerShell will then execute the script once the Virtual Machine is ready.

If you want to execute multiple scripts you can certainly do that with ‘,’ comma separated however one of them needs to be the master script that’s going to call the child scripts, I haven’t tried with multiple “commandToExecute” because the right was it to call one script at a time.

Now this is kind of open for all storage account but if you want to secure the access to storage account and the scripts you can use “protectedSetting”, something similar to this.

Template is available here:I have removed password from the template, i just don’t want people to know how bad i am with passwords, but hey it’s about quickly showing people how to do things.

https://github.com/Hardeepbhamra/cloud-infrastructure/tree/master/07-ARM-Virtual-Machine-Extension-Script

Leave a Reply

Your email address will not be published. Required fields are marked *