How to set environment variables in Azure ARM templates

喜你入骨 提交于 2019-12-10 14:32:31

问题


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?


回答1:


Windows

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')]"
        }
    }
}



回答2:


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.



来源:https://stackoverflow.com/questions/41016360/how-to-set-environment-variables-in-azure-arm-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!