Search code examples
azureazure-resource-managerazure-resource-groupazure-container-instances

Setting ENV in Azure Container Instances Deployment


I tried to automate my deployment of a Docker container to an Azure resource group following the docs on https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-keyvault-parameter#deploy-a-key-vault-and-secret and https://gallery.azure.com/artifact/20161101/microsoft.containerinstances.1.0.8/Artifacts/mainTemplate.json.

I was able to deploy my application successfully, including the retrieval of encrypted secrets from Vault. I'm now struggling to set ENVs for my container, both secrets and normal ENVs. Even though there is a way to set ENVs in the az container API, I cannot find anything in the docs of the resource group deployment API. How can I pass ENVs to my Azure container?


Solution

  • The snippet of the json template you need is as follows (the full template is here)

    "name": "[toLower(parameters('DeploymentName'))]",
    "type": "Microsoft.ContainerInstance/containerGroups",
    "properties": {
        "containers": [
            {
    
                "environmentVariables": [
                    {
                        "name": "CertificateName",
                        "value": "[parameters('CertificateName')]"
                    },
                ],