ARM Template containing config settings for web app

一世执手 提交于 2019-12-02 07:50:13

I try to create WebApp with the appsetting and logs, it works correctly for me. I created the project using Visual Studio. The following is my detail steps.

1.Create the Azure Resource Project

2.Select the WebApp template

3.Click the deploy file then right click and remove the unnecessary resource

4.Add the Appsetting Resource for the WebApp

5.Add the logs code for the Azure WebApp

{
          "apiVersion": "2015-08-01",
          "name": "logs",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off"
              },
              "azureBlobStorage": {
                "level": "[variables('Level')]",
                "sasUrl": "xxxx"
              }
            },
            "httpLogs": {
              "fileSystem": {
                "enabled": false
              },
              "azureBlobStorage": {
                "enabled": true,
                "sasUrl": "xxxxxx"
              }
            },
            "failedRequestsTracing": {
              "enabled": "[parameters('enableFailedRequestTracing')]"
            },
            "detailedErrorMessages": {
              "enabled": "[parameters('enableDetailedErrorMessages')]"
            }
          }
        }

6.Right click the project and select the deploy

7.Check the result from the Output and Azure portal

The whole arm template:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "enableFailedRequestTracing": {
      "type": "bool"
    },
    "enableDetailedErrorMessages": {
      "type": "bool"
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]",
    "Level": "Error"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "name": "appsettings",
          "type": "config",
          "apiVersion": "2015-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]"
          ],
          "tags": {
            "displayName": "appsettings"
          },
          "properties": {
            "key1": "value1",
            "key2": "value2"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "logs",
          "type": "config",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
            "applicationLogs": {
              "fileSystem": {
                "level": "Off"
              },
              "azureTableStorage": {
                "level": "Off"
              },
              "azureBlobStorage": {
                "level": "[variables('Level')]",
                "sasUrl": "xxxxx"
              }
            },
            "httpLogs": {
              "fileSystem": {
                "enabled": false
              },
              "azureBlobStorage": {
                "enabled": true,
                "sasUrl": "xxxx"
              }
            },
            "failedRequestsTracing": {
              "enabled": "[parameters('enableFailedRequestTracing')]"
            },
            "detailedErrorMessages": {
              "enabled": "[parameters('enableDetailedErrorMessages')]"
            }
          }
        }
      ]
    }

  ]
 }

I have experienced similar issues. We fixed this using dependsOn rules. You should add dependsOn rules to split the processing of each config section. It seems like otherwise there can occur problems, for instance ...missing settings.

Arm snippet:

{
    "name": "[variables('ExampleAppName')]",
    "type": "Microsoft.Web/sites",
    "location": "[resourceGroup().location]",
    "apiVersion": "2015-08-01",
    "kind": "api",
    "dependsOn": ["[resourceId('Microsoft.Web/serverfarms', variables('applicationPlanName'))]"],
    "tags": {
        "displayName": "Example App"
    },
    "properties": {
        "name": "[variables('ExampleAppName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('applicationPlanName'))]",
        "clientAffinityEnabled": "false"
    },
    "resources": [{
        "name": "web",
        "type": "config",
        "apiVersion": "2015-08-01",
        "dependsOn": ["[resourceId('Microsoft.Web/sites', variables('ExampleAppName'))]"],
        "tags": {
            "displayName": "webconfig Example App"
        },
        "properties": {
            "alwaysOn": "true"
        }
    },
    {
        "apiVersion": "2015-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": ["[resourceId('Microsoft.Web/sites', variables('ExampleAppName'))]",
        "[resourceId('Microsoft.Web/sites/config', variables('ExampleAppName'), 'web')]"],
        "tags": {
            "displayName": "appsettings Example App"
        },
        "properties": {
            "EXAMPLE1": "[parameters('EXAMPLE1')]",
            "EXAMPLE2": "[parameters('EXAMPLE2')]"
        }
    },
    {
        "name": "logs",
        "type": "config",
        "apiVersion": "2015-08-01",
        "dependsOn": ["[concat('Microsoft.Web/sites/', variables('ExampleAppName'))]",
        "[resourceId('Microsoft.Web/sites/config', variables('ExampleAppName'), 'appsettings')]"],
        "tags": {
            "displayName": "logs Example App"
        },
        "properties": {
            "applicationLogs": {
                "fileSystem": {
                    "level": "Warning"
                }
            },
            "httpLogs": {
                "fileSystem": {
                    "retentionInMb": "35",
                    "enabled": true
                }
            },
            "detailedErrorMessages": {
                "enabled": false
            }
        }
    }]
}

For additional information you can read my post: Click here!

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