Slowacki
Slowacki

Reputation: 490

Override an environmental variable on Azure App Service without using the app settings

I need to override one of the default Azure environmental variables. The most obvious way is to add an app setting with the same name, which will override the environmental variable, however, I'd like to approach it in a different way, as this variable is essentially not an app settings.

My perfect approach would be to set it during an ARM deployment, but after checking Azure Resource Explorer, it looks like the environmental variables are not exposed anywhere. Are those stored in some files on the machine that could be transformed during a deployment by any chance? That could be another solution.

Upvotes: 0

Views: 1557

Answers (1)

Fei Han
Fei Han

Reputation: 27793

My perfect approach would be to set it during an ARM deployment, but after checking Azure Resource Explorer, it looks like the environmental variables are not exposed anywhere.

In ARM template, we could define the Application Settings to apply to the Web App. As David Ebbo said, please try to explicitly set WEBSITE_DYNAMIC_CACHE to 0 from the appsettings.

{
    "name": "appsettings",
    "type": "config",
    "apiVersion": "2015-08-01",
    "dependsOn": [
        "[concat('Microsoft.Web/sites/', variables('webSiteName'))]"
    ],
  "tags": {
    "displayName": "WebAppSettings"
  },
  "properties": {
    "WEBSITE_DYNAMIC_CACHE": "0"
  }
}

Update:

I do not find a resource/section in ARM template could be used to directly inject an environment variable. XDT Transform provide a way to inject environment variables, if possible, you could try to use it.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
  <system.webServer> 
    <runtime xdt:Transform="InsertIfMissing">
      <environmentVariables xdt:Transform="InsertIfMissing">    
         <add name="WEBSITE_DYNAMIC_CACHE" value="0" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />    
      </environmentVariables>
    </runtime> 
  </system.webServer>
</configuration>

Upvotes: 1

Related Questions