The key guiding principles of the Farmer API are (in order):
Farmer works on a simple, consistent process:
webApp
resource represents both the Microsoft.Web/sites
and Microsoft.Web/serverfarms
resources. In addition, it optionally also provides simplified access to an Microsoft.Insights/components
.The diagram below illustrates how Farmer resources map to ARM ones:
In this example, we create a storage account and web app in Farmer, which maps five different ARM template resources. As you can see, resources in Farmer are declared at a higher level of abstraction than ARM template resources. This makes things much simpler to reason about, and quicker to author.
All Farmer resources follow the same approach:
Here’s an example web application.
let myWebApp = webApp {
name "mystorage"
setting "myKey" "aValue"
sku Sku.B1
always_on
app_insights_off
worker_size WorkerSize.Medium
number_of_workers 3
run_from_package
}
webApp { }
builder defines the start and end of the definition of the web application.name
and setting
.always_on
are simple declarative markers.You can view details of all farmer resources in the resource guide.
The diagram above can be shown in code as follows:
/// An Azure Storage account with a container.
let storage = storageAccount {
name "astorageaccount"
add_public_container "myContainer"
}
/// An Azure App Service with built-in App Insights.
let app = webApp {
name "awebapp"
setting "storageKey" storage.Key // pull in the storage key to an app setting
depends_on storage // state that this web app depends on the storage account
}
/// An ARM deployment with both of the above resources attached
let deployment = arm {
location Location.NorthEurope
add_resource storage
add_resource app
}
// Write the ARM template out to myTemplate.json
let filename =
deployment.Template
|> Writer.toJson
|> Writer.toFile "myTemplate"