1
votes

I'm trying to automate deployment on azure using azure templates and packer.

I have my packer ami(?) already built, with application (java fat jar) included.

Now, my application connects to azure evnet hub which is deployed at the same time as my vm and declared in the same json template.

I would like to pass connection properties to vm as environment variables in my arm template. Is it possible with azure templates? I've found a similar question on SO, asked half a year ago, without an answer. But maybe something has changed since then? How do people resolve such issues on azure? Terraform is not an option sadly, it doesn't cover other parts of azure infrastructure.

2

2 Answers

2
votes

I would like to pass connection properties to vm as environment variables in my arm template. Is it possible with azure templates?

As 4c74356b41 said, template does not support this directly. According to your scenario, I suggest you could use Custom Script Extension.

The Custom Script Extension downloads and executes scripts on Azure virtual machines. This extension is useful for post deployment configuration, software installation, or any other configuration / management task.

Azure custom script extension supports Linux and Windows, you could write a script that configure connection properties to vm and use extension to execute on your VMs. The custom script extension template example is like below:

 "resources": [
                {
                    "type": "extensions",
                    "name": "CustomScriptExtension",
                    "apiVersion": "2015-06-15",
                    "location": "[resourceGroup().location]",
                    "dependsOn": [
                        "[variables('vmName')]"
                    ],
                    "properties": {
                        "publisher": "Microsoft.Compute",
                        "type": "CustomScriptExtension",
                        "typeHandlerVersion": "1.8",
                        "autoUpgradeMinorVersion": true,
                        "settings": {
                            "fileUris": [
                                "[concat(parameters('_artifactsLocation'), '/', variables('ScriptFolder'), '/', variables('ScriptFileName'), parameters('_artifactsLocationSasToken'))]"
                            ],
                            "commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('scriptFolder'), '/', variables('scriptFileName'), ' ', variables('scriptParameters'))]"
                        }
                    }
                }
            ]

They could find many examples about this extension on Git Hub.

3
votes

No, you cannot directly set env. variables to a VM using ARM templates, but you could deploy a script extension using an ARM template which would do that for you.