Skip to main content
Setting App Service connection strings in ARM
  1. Posts/

Setting App Service connection strings in ARM

·144 words·1 min
Christoph Petersen
Author
Christoph Petersen

For automatic deployment of test environments we are spinning up App Service instances and want to automatically set connection strings for the database and other services in the same template.

According to the Azure Resource Manager documentation the property connectionStrings of the Microsoft.Web/sites/config resource type can be used. Alas, when I use that property the connection strings are not configured on the App Service.

I found some older template examples that set the connection string as part of the Microsoft.Web/sites resource type:

{
    "type": "Microsoft.Web/sites",
    "apiVersion": "2018-11-01",
    "name": "[variables('nameSite')]",
    "location": "[variables('locationFarm')]",
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', variables('nameFarm'))]",
        "[resourceId('Microsoft.Sql/servers/databases', variables('nameSqlServer'), variables('nameSqlDatabase'))]"
    ],
    "kind": "app",
    "properties": {
        "enabled": true,
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('nameFarm'))]",
        "siteConfig": {
            "connectionStrings": [
                {
                    "name": "MyDb",
                    "connectionString": "[concat('Server=tcp:', variables('nameSqlServer'), '.database.windows.net,1433;Initial Catalog=', variables('nameSqlDatabase'), ';Persist Security Info=False;User ID=', variables('usernameSql'), ';Password=', parameters('PasswordSql'), ';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]",
                    "type": "SQLAzure"
                }
            ]
        }
    }
}

Now the connection strings are set properly.

Related

Inventory VMs with PowerShell DSC and Log Analytics

·501 words·3 mins
Photo by Matt Artz on Unsplash In many scenarios there is the requirement to enrich or lookup data with meta information from the infrastructure. In this scenario a file with machine, location and other meta information was placed during deployment on the VM for both Azure and AWS.

Automation in Azure

·1125 words·6 mins
Deploying resources and workloads at scale requires a healthy amount of automation. Automation helps to deliver consistent and repeatable results. I’ve tried to categorize some of the technology and provide some pointers to areas of application and pros and cons.

Tracking changes to Azure Resource Manager providers

·65 words·1 min
A colleague of mine, Tyler Ayers, has written a pretty neat Azure Function that tracks changes made to Azure Resource Manager Providers (ARM) and show these changes in a timeline.