The tweet shown above caught my attention, and I wanted to give it a try. Yes! Without a doubt, we deployed a few resources in a development environment using Farmer. I thoroughly enjoyed the new and easy way of building ARM templates.
The Farmer documentation is super easy to follow, in my localhost below tools were available already
The minimum version of Azure CLI should be 2.5.0. This snippet gets the latest Az CLI.
To begin with, let us install the Farmer .NET template
dotnet new -i Farmer.Template
Create a new framer project, and it is super easy. The below one-liner snippet will take care of it. Yes, it will create an F# console application (Farmer Application)
dotnet new -i Farmer.Template
I am new to F# as well. But, I managed to understand the basics, which allowed me to deliver the ARM template at ease. If you know F#, then it’s a cakewalk. We are good till here. Yes, no errors encountered, and that’s a good sign. Keep moving! Let’s build and deploy the ARM template to create a storage account.
Storage Account
Build ARM Template and Deploy….
Replace the Progam.fs file with the below code and replace the values for azResourceGroup, values for storageAccount (name, sku and add_private_container)
open Farmer
open Farmer.Builders
open Farmer.Deploy
open System
let azResourceGroup = "Az-Demo-RGP01"
let storage = storageAccount {
name "wintellisysdemo"
sku Storage.Standard_ZRS
add_private_container "democontainer"
}
let deployment = arm {
location Location.NorthEurope
add_resource storage
}
deployment
|> Writer.quickWrite "storageAccount-template"
deployment
|> Deploy.execute azResourceGroup Deploy.NoParameters
|> printfn "%A"
dotnet run
What it does?
It’ generated an ARM template for the storage account and stored it in a file name “storageAccount-template.json”. Then deploys the ARM to Azure environment. Below is the ARM template JSON content for your reference.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2018-07-01",
"kind": "StorageV2",
"location": "northeurope",
"name": "storageaccount01",
"resources": [
{
"apiVersion": "2018-03-01-preview",
"dependsOn": [
"storageaccount01"
],
"name": "default/private-demo-container",
"properties": {
"publicAccess": "None"
},
"type": "blobServices/containers"
}
],
"sku": {
"name": "Standard_ZRS"
},
"type": "Microsoft.Storage/storageAccounts"
}
]
}
I call the dotnet run with verbosity medium.
dotnet run -v m
Navigate to Azure Portal and search for the storage account you created. Underneath the containers, private-demo-container should be accessible.
How is the authentication working?
From Local Host…
It gets the context information from the Az CLI. If not logged in, prompts appear. However, if you are managing multiple subscriptions, then set the subscription in which you need to experiment.
In our next blog post, we will take a tour of Farmer and walk through some real-world examples with Azure DevOps pipelines. Stay tuned! Follow us on @Wintellisys to know more information about cloud services and automation.