I want to set the environment on my deployments in the ARM-template to guarantee the environment is the same across machines. Is there a way to set environment variables for a virtual machine created with an ARM template?
You can use a Custom Script Extension to invoke SETX
at deployment time. Add a nested resource to the resources
array of your VM resource. This example invokes SETX MyEnvironmentPrefix (environmentPrefix-parameter-value) /m
on the target machine:
{
"apiVersion": "2017-12-01",
"type": "extensions",
"name": "SetEnvironmentVar",
"comments": "Sets the MyEnvironmentPrefix system env var",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": true,
"settings": {
"commandToExecute": "[concat('SETX MyEnvironmentPrefix ', parameters('environmentPrefix'), ' /m')]"
}
}
}
I don't think there is a direct way to do that (looking at the schema), but you could always implement something custom, Script extension or DSC extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With