Our Azure infrastructure has some configurations that our developers need to know like the name of the currently active AKS cluster and APIM instance. We store these configurations in an Azure App Configuration instance and expose them as an API through an Azure App Service Web App that is written in NodeJS. This post shows how we provision the NodeJS Web App with an ARM template.
We can provision the App Service Plan and App Service from the portal, and then setup deployment of a GitHub repository for the NodeJS application. But I wanted it to be 100% automated without setting up anything, so I decided to try ARM templates.
The ARM template explained
An ARM templates contains of 4 sections, parameters
, variables
, resources
, and outputs
. We will focus on only two of them. parameters
and resources
.
In parameters I defined a name
for the site, a connectionString
for the App Configuration Service, a repositoryUrl
of the NodeJS application, and a branchName
of the application that I want to deploy.
In the resources
section, I defined 4 resources. an App Service Plan that has the type Microsoft.Web/serverfarms
, an App Service with type Microsoft.Web/sites
, a configuration for the App Service with type Microsoft.Web/sites/config
, and the hostname binding so we can reach the web app with type Microsoft.Web/sites/hostNameBindings
.
App Service Plan
You get one free App Service Plan with SKU B1 for one month and subscription, at least for now. If you automate the provisioning of the entire setup as described in this post, you could trigger it with an Azure Runbook if you want.
App Service
The App Service depends on the App Service Plan. In ARM we can define this dependency that has to exist with dependOn
. This example is a simplification and http only. You shouldn’t run this in production.
This App Service section also describes 2 resources, sourcecontrols
where I defined the GitHub repository, and config
where I store the connectionString for Azure App Configuration. Since I chose type Custom
for my connectionString, I can access the value from my NodeJS application with the prefix key CUSTOMCONNSTR_
. The fully key would be CUSTOMCONNSTR_AppConfigConnString
. The connectionString is stored as an environment variable that my NodeJS application can access with process.env.CUSTOMCONNSTR_AppConfigConnString
.
App Service Configuration and hostname binding
In these resource, we configure our App Service. I exported these resources directly from the portal and made a few changes like the scmType
which is in my case GitHub.
NodeJS Application
The NodeJS application is in a separate GitHib repository that uses the azure/app-configuration module. Every commit to the branch that you defined when deploying the ARM template will deploy a new version and restart the application.
Conclusion
This ARM template will deploy App Service Plan, App Service, and deploy the NodeJS application.
az deployment group create --name "YOUR_WEBAPP" --resource-group "YOUR_RG" --template-file PATH_TO_YOUR_ARM_TEMPLATE