Set ARM Template Web appSetting

后端 未结 2 550
既然无缘
既然无缘 2021-01-06 15:48

How can I use ARM to deploy applicationsettings to a website?


1 When running the following in VS ARM Deploy json:

....
     \"resources\": [
           


        
相关标签:
2条回答
  • 2021-01-06 16:19

    Thanks to @Alexander-s and @davidebbo

    With PowerShell

    After the Deployment (without appsettings) has succeeded. Then run this to overwrite the appsettings completely.

    $subscriptionID = {...}
    Add-AzureRmAccount
    Set-AzureRmContext -SubscriptionID $subscriptionID
    
    # List appsettings
    $resource = Invoke-AzureRmResourceAction -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName <webSiteName>/appsettings -Action list -ApiVersion 2015-08-01 -Force
    $resource.Properties
    
    # SET list
    $appsettingTest1Value = "testValue1"
    $appsettingTest2Value = "testValue2"
    $PropertiesObject = @{
        appsettingTest1=$appsettingTest1Value,
        appsettingTest2=$appsettingTest2Value,
        WEBSITE_NODE_DEFAULT_VERSION: "4.4.7"
      }
    New-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName <webSiteName>/appsettings -ApiVersion 2015-08-01 -Force
    

    With ARM Deployment JSON

    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Web/serverFarms/', parameters('hostingPlanName'))]",
        "[concat('Microsoft.Storage/storageAccounts/', variables('storage_account_name'))]",
        "[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]",
        "[resourceId('Microsoft.Sql/servers/databases', variables('sqlserverName'), parameters('database_name_auth'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty",
        "displayName": "Website"
      },
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "web",
          "type": "config",
          "dependsOn": [
            "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
          ],
          "properties": {
            "netFrameworkVersion": "[parameters('dotnet_version')",
            "use32BitWorkerProcess": "[parameters('use32bit_worker_process')",
            "webSocketsEnabled": false,
            "alwaysOn": "[parameters('enable_always_on')]",
            "requestTracingEnabled": true,
            "httpLoggingEnabled": true,
            "logsDirectorySizeLimit": 40,
            "detailedErrorLoggingEnabled": true
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "appsettings",
          "type": "config",
          "dependsOn": [
            "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
          ],
          "properties": {
            "appsettingTest1": "[parameters('appsettingTest1Value')]",
            "appsettingTest2": "[parameters('appsettingTest2Value')]"
          }
        },
        {
          "apiVersion": "2015-08-01",
          "name": "connectionstrings",
          "type": "config",
          "dependsOn": [
            "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
          ],
          "properties": {
            "dbconnstringTest1": {
              "value": "[concat('Data Source=tcp:', reference(concat('Microsoft.Sql/servers/', variables('sqlserverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', parameters('database_name_auth'), ';User Id=', parameters('administratorLogin'), '@', variables('sqlserverName'), ';Password=', parameters('administratorLoginPassword'), ';')]",
              "type": "SQLServer"
            },
            "AzureWebJobsConnectionString": {
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storage_account_name'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storage_account_name')), '2015-05-01-preview').key1,';')]",
              "type": "Custom"
            }
          }
        }
      ]
    },
    
    0 讨论(0)
  • 2021-01-06 16:21

    Answer 1

       $webapp = Get-AzureRmWebApp -Name $webSiteName
       $webapp.SiteConfig.AppSettings
    

    Answer 2

    Here what I have in my ARM template, and it works fine:

      "resources": [
        {
          "apiVersion": "2015-08-01",
          "location": "[resourceGroup().location]",
          "type": "config",
          "name": "appsettings",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {...}
        },
        {
          "apiVersion": "2015-08-01",
          "location": "[resourceGroup().location]",
          "type": "config",
          "name": "web",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', variables('webSiteName'))]"
          ],
          "properties": {
            "alwaysOn": true
          }]
    

    As you can see I set AppSettings as separate resource under website. Try it, should work.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题