This tutorial walks you through creating multiple web applications that will share a common web server. We’ll cover the following steps:
Create a standard web app as normal:
let primaryWebApp = webApp {
name "primarywebapp"
sku WebApp.Sku.F1
}
Create a second web app, but this time link to the service plan that is part of the first web app:
let secondaryWebApp = webApp {
name "secondarywebapp"
link_to_service_plan primaryWebApp.ServicePlanName
link_to_app_insights primaryWebApp.AppInsightsName
}
You can now add both web apps to the arm { }
block for deployment:
let template = arm {
location Location.NorthEurope
add_resource primaryWebApp
add_resource secondaryWebApp
}
Rather than “piggy back” on a “primary” web app, you can also opt to create a dedicated service plan and app insights instances and configure all web apps to use them. This is a slightly more verbose option, but you may find it clearer, and as we’ll see shortly, it can sometimes be useful to declare these instances outside of the web app:
let plan = servicePlan {
name "theFarm"
sku WebApp.Sku.F1
}
let ai = appInsights {
name "insights"
}
let aWebApp = webApp {
name "primarywebapp"
link_to_service_plan plan
link_to_app_insights ai
}
let anotherWebApp = webApp {
name "secondarywebapp"
link_to_service_plan plan
link_to_app_insights ai
}
As you are creating the plan and AI instances yourself, you also need to remember to add them to the
arm { }
block!
F# has excellent support for working with collections of data, including creating data. Let’s assume we wanted to create four web apps, each with a name “mywebapp-{index}” e.g. “mywebapp-1” etc. We can use F#‘s list comprehensions to create four web apps quickly and easily.
let webApps : IBuilder list = [
for i in 1 .. 4 do
webApp {
name ("mywebapp-" + string i)
link_to_service_plan plan
link_to_app_insights ai
}
]
The key parts to note are:
[ ]
, which in F# signify a list of some data.for .. in .. do
syntax to iterate over numbers 1 to 4, assigning each value to i
.List comprehensions in F# are very powerful. You can use this approach with a specific set of names that are themselves a list as well e.g.
let planets = [ "jupiter"; "mars"; "pluto"; "venus" ]
let webApps = [
for planet in planets do
...
]
Once you have created a list of web apps, you can add them all at once to the ARM builder using the add_resources
keyword:
let template = arm {
...
add_resources webApps
}