3

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


1 When running the following in VS ARM Deploy json:

....
     "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[variables('skuName')]",
        "capacity": "[variables('skuCapacity')]"
      },
      "properties": {
        "name": "[variables('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.Web/serverFarms/', variables('hostingPlanName'))]"
      ],
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]": "empty",
        "displayName": "Website"
      },
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "web",
          "type": "config",
          "dependsOn": [
            "[concat('Microsoft.Web/Sites/', variables('webSiteName'))]"
          ],
          "properties": {
            "netFrameworkVersion": "4.5.2",
            "use32BitWorkerProcess": true,
            "webSocketsEnabled": false,
            "alwaysOn": false,
            "requestTracingEnabled": true,
            "httpLoggingEnabled": true,
            "logsDirectorySizeLimit": 40,
            "detailedErrorLoggingEnabled": true,
            "appSettings": [
              {
                "name": "testn",
                "value": "testv"
              }
            ],
            "connectionstrings": [
              {
                "name": "testn",
                "value": "testv",
                "type": "SQLServer"
              }
            ]
          }
        }
      ]
    }
  ],

Output is;

VERBOSE: Performing the operation "Creating Deployment" on target "testdeploy3".
VERBOSE: 4:44:42 PM - Template is valid.
...
VERBOSE: 4:45:17 PM - Resource Microsoft.Web/sites/config 'testwebadtzmdritygpo/web' provisioning status is succeeded

...
ProvisioningState       : Succeeded

Double checking in the Portal shows appsettings and connectionstrings have NOT been created

Question 1: How do I query with PowerShell a website's config properties?

Question 2: How can I use ARM to deploy applicationsettings to a website?

2 Answers 2

4

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"
        }
      }
    }
  ]
},
Sign up to request clarification or add additional context in comments.

1 Comment

here we are creating parent and child resource thus name of child resource is resolvable. But what if parent resource is already exists and we just need to add child resource. Like if I can have Cloud DNS the how to add Record Set in it? I am not able to find how to set name.
1

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.

4 Comments

Is the resources 'node' under "Microsoft.Web/sites" or "Microsoft.Web/serverfarms"?
Answer 1. maybe not. A lot of NameValuePair and Dictionary conversion to make sure am only adding additional appsettings, and not removing any existing ones.
Answer 2 if I only want to insert one. See below for 'own answer' for multiple values and connection strings. Hints from: github.com/davidebbo/AzureWebsitesSamples/blob/…
Under web sites

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.