Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Last active December 4, 2017 10:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdurandeu/c476b3ef01b094fd5fe9d6cefe4f3c36 to your computer and use it in GitHub Desktop.
Save sdurandeu/c476b3ef01b094fd5fe9d6cefe4f3c36 to your computer and use it in GitHub Desktop.
Azure ARM Template Samples

ARM Templates Samples

Azure App Service

Including how to:

  • Set Connection Strings
  • Set app settings with a Cosmos DB Accunt Key, the Azure Storage Key and App Insights Instrumentation Key
  • Output the Website Publishing Username and Password
  • AlwaysOn turned on
{
...
"resources": [
  {
    "comments": "",
    "type": "Microsoft.Web/sites",
    "kind": "WebApp",
    "name": "[parameters('AppServiceApiName')]",
    "apiVersion": "2015-08-01",
    "location": "[resourceGroup().location]",
    "scale": null,
    "properties": {
      "name": "[parameters('AppServiceApiName')]",
      "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('ServerFarmName'))]",
      "siteConfig": {
        "AlwaysOn": true,
        "cors": {
          "allowedOrigins": "[parameters('FrontEndSiteUrlForCors')]"
        },
        "connectionStrings": [
          {
            "name": "AzureWebJobsDashboard",
            "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value, ';EndpointSuffix=core.windows.net')]",
            "type": "Custom"
          },
          {
            "name": "AzureWebJobsStorage",
            "connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value, ';EndpointSuffix=core.windows.net')]",
            "type": "Custom"
          }
        ]
      }
    },
    "dependsOn": [
      //  NOTE: for simplicity these resources are not included in this template
      "[resourceId('Microsoft.Web/serverfarms', parameters('ServerFarmName'))]",
      "[resourceId('Microsoft.Storage/storageAccounts', parameters('StorageAccountName'))]",
      "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('CosmosDBAccountName'))]",
      "[resourceId('Microsoft.Insights/components', parameters('AppInsightsName'))]"
    ],
    "resources": [
      {
        "name": "appsettings",
        "type": "config",
        "apiVersion": "2015-08-01",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', parameters('AppServiceApiName'))]"
        ],
        "properties": {
          "CosmosDb:Key": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('CosmosDBAccountName')), providers('Microsoft.DocumentDB', 'databaseAccounts').apiVersions[0]).primaryMasterKey]",
          "CosmosDb:Endpoint": "[reference(concat('Microsoft.DocumentDb/databaseAccounts/', parameters('CosmosDBAccountName'))).documentEndpoint]",
          "AzureStorageConnectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value, ';EndpointSuffix=core.windows.net')]",
          "ApplicationInsights:InstrumentationKey": "[reference(resourceId('Microsoft.Insights/components', parameters('AppInsightsName')), providers('Microsoft.Insights', 'components').apiVersions[0]).InstrumentationKey]"
        }
      }
    ]
  },
  {
      "name": "[parameters('ServerFarmName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-08-01",
      "sku": {
        "name": "[parameters('ServerFarmSku')]"
      },
      "dependsOn": [],
      "tags": {
        "displayName": "ServerFarm"
      },
      "properties": {
        "name": "[parameters('ServerFarmName')]",
        "numberOfWorkers": 1
      }
    }
],
"outputs": {
  "ApiPublishingUserName": {
    "type": "string",
    "value": "[list(resourceId('Microsoft.Web/sites/config', parameters('AppServiceApiName'), 'publishingcredentials'), providers('Microsoft.Web', 'sites').apiVersions[0]).properties.publishingUserName]"
  },
  "ApiPublishingPassword": {
    "type": "string",
    "value": "[list(resourceId('Microsoft.Web/sites/config', parameters('AppServiceApiName'), 'publishingcredentials'), providers('Microsoft.Web', 'sites').apiVersions[0]).properties.publishingPassword]"
  },
  "ApiPublishingUrl": {
    "type": "string",
    "value": "[concat(parameters('AppServiceApiName'), '.scm.azurewebsites.net:443' )]"
  }
}
}

Execute Operations Manually via PowerShell

  • Get publish credentials via ARM:
Invoke-AzureRmResourceAction -ResourceId /subscriptions/27cafca8-XXXX-4264-b399-45d0c9cca1ab/resourceGroups/testarmdeployment2/providers/Microsoft.Web/sites/mysite/config/publishingcredentials -Action list -ApiVersion 2015-08-01
  • List operations of a resource provider (listKeys, list, etc.)
Get-AzureRmProviderOperation -OperationSearchString "Microsoft.Web/sites/*" | where {$_.Operation -like "*list*"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment