Azure ARMory: Including customData without a fuss
Include a plain text cloud-init file using secureString variable types and backticks in your Azure ARM template

Beware! I’m a smidge new to Azure and only recently started fooling around with the template deployment functions. That said… even though it requires quite a shift going from manpages to Azure technical propaganda… it appears ARM templates are fairly straight forward after some initial demystification.
When I went to download my template after using the Azure portal to set up a virtual machine deployment I was a bit dismayed to see that the customData I had included as a cloud-init compatibleuser-data.txt
data had somehow evaporated and not made it in to the template.json
or the parameters.json
files.
Turns out this isn’t a very common scenario. So lets get right to it.
First off your downloaded template.json
for a virtual machine will(should) already contain the variable definition for customData
under the root parameters
key.
{
"parameters": {
"customData": {
"type": "secureString"
}
}
}
Under the osProfile
key further down the file you will(should) also see the customData
placement and code to include the parameter.
{
"resources": [
{
"properties": {
"osProfile": {
"customData": "[parameters('customData')]"
}
}
}
]
}
Assuming you are using the CLI tools provided for Linux/MacOS and not Powershell you can now run the following to include your customData
during deployment by way of the magic shell backticks and the base64
tool set to 0 (disabled) wrapping width.
az deployment group create --resource-group Development --template-file template.json --parameters @parameters.json --parameters customData="`base64 -w 0 cloud-init`"
Enjoy!