iac,

Parameters in Farmer - IaC with Azure

Sven Malvik Sven Malvik Connect Oct 10, 2020 · 4 mins read
Parameters in Farmer - IaC with Azure

This is part 2 of my learning adventure of Farmer for Azure resource deployments. This time, I wanted to look at parameters, variables, outputs and expressions.

Passing Outputs to another Resource

I created a Web App with a dependency to a storage account. As shown below, the storage key kan simply be passed to the web application.

let sa = storageAccount {
    name "demo-sma75-sa"
}

let webAppConfig = webApp {
    name "demo-webapp"
    setting "storageKey" sa.Key
}

The generated ARM template shows us the storage key.

"appSettings": [
    {
        "name": "storageKey",
        "value": "[concat('DefaultEndpointsProtocol=https;AccountName=demosma75sa;AccountKey=', listKeys('demosma75sa', '2017-10-01').keys[0].value)]"
    },

Farmer knows that the Web Application needs to be deployed before the storage account, so we don’t need to explicitly declare this. However, you can specify this explicitly with depends_on.

let webAppConfig = webApp {
    name "demo-webapp"
    setting "storageKey" sa.Key
    depends_on [ sa ]
}

depends_on [ sa ] gave me this error message.

/Users/sma/git/farmer-demo1/Program.fs(12,5): error FS0041: No overloads match for method 'DependsOn'.Known types of arguments: WebAppConfig * StorageAccountConfig listAvailable overloads: - member WebAppBuilder.DependsOn : state:WebAppConfig * builder:CoreTypes.IBuilder -> WebAppConfig // Argument 'builder' doesn't match - member WebAppBuilder.DependsOn : state:WebAppConfig * resource:CoreTypes.IArmResource -> WebAppConfig // Argument 'resource' doesn't match - member WebAppBuilder.DependsOn : state:WebAppConfig * resourceName:CoreTypes.ResourceName -> WebAppConfig // Argument 'resourceName' doesn't match [/Users/sma/git/farmer-demo1/FarmerApp.fsproj]

I do not know F# yet, so this error might be obvious for others, but I have an idea how to solve this (part of a later post). For me it was just painful because my example is directly from the documentation.

Anyway, the storage key was successfully set under Application Settings.

App Service setting with storage keyApp Service setting with storage key

Looking at the API for Web App we see all the configurations we can and have to set if we want to understand what happens and gets created. I.e. can we set app_insights_off to avoid creating an instance for us.

Created Azure resources with Farmer for default WebAppCreated Azure resources with Farmer for default WebApp

No Support for Variables and Parameters

Farmer doesn’t support ARM variables or parameters. The reasons for that are:

  • Codebase gets more complex
  • API surface area gets more complex
  • Expressions capabilities inside ARM templates like concat inside a variable that depends on another variable - hard to do without increasing the complexity

The Farmer developers recommend to put Farmer as part of a build script to generate ARM templates, rather than committing into source control.

  • Simplifies the code base
  • Instead of using the error prone and limited expression capabilities of ARM templates, you can use a proper programming language for conditional logic for creating the ARM template
  • Deployments e.g. inside the Azure Portal are much easier to read because there are no placeholders or variables but just values

Here’s the code for entire application

open Farmer
open Farmer.Builders
open System

let createWebApp theLocation =

    let sa = storageAccount {
        name "demo-sma-sa"
    }

    let webapp = webApp {
        name "demo-sma75-webapp"
        app_insights_off
        setting "storageKey" sa.Key
    }

    arm {
        // Our location we set previously
        location theLocation
        add_resource sa
        add_resource webapp
    }

createWebApp Location.WestEurope
|> Deploy.execute "farmer-rg" Deploy.NoParameters

Next Steps

This example was pretty basic, but it might show that we can pass parameters as input values and all created resources get the location set with the actual value rather then a reference. What interests me next is how I can deploy Azure App Configuration or Azure API Management with Farmer. Those resources are not part of Farmer yet.

Join Newsletter
Get the latest updates right in your inbox. I never spam!
Sven Malvik
Written by Sven Malvik

Latest Stories

Introduction to Farmer - IaC with Azure

As many companies move their services to the cloud, the way we interact with the cloud, the tooling, becomes more important. In Azure we ...

Sep 26, 2020

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Azure API Management with ARM

Deploying an ARM template (Azure Resource Management)-template from GitHub is the simplest way of provisioning an instance of API Managem...

Mar 28, 2020

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021

ARM for NodeJS Azure Web App with App Configuration Integration

Our Azure infrastructure has some configurations that our developers need to know like the name of the currently active AKS cluster and A...

Jun 13, 2020

Using Feature Flags with Azure App Configuration

Sometimes we would like to test a new feature of an application. Or we would like to disable code junks because they are not fully implem...

May 16, 2020

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

How to Reference Key Vault Secrets in Azure API Management

In an enterprise, an Azure API Management instance is often shared by many teams and many developers. The developers may all have access ...

Feb 05, 2021

Latest Stories

Introduction to Farmer - IaC with Azure

Introduction to Farmer - IaC with Azure

As many companies move their services to the cloud, the way we interact with the cloud, the tooling, becomes more important. In Azure we ...

Sep 26, 2020

Event-Driven Infrastructure with App Configuration

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Using App Configuration in Azure DevOps

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Introduction to Azure API Management

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

How To Manage Azure Virtual Machines

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Azure API Management with ARM

Azure API Management with ARM

Deploying an ARM template (Azure Resource Management)-template from GitHub is the simplest way of provisioning an instance of API Managem...

Mar 28, 2020

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021

ARM for NodeJS Azure Web App with App Configuration Integration

ARM for NodeJS Azure Web App with App Configuration Integration

Our Azure infrastructure has some configurations that our developers need to know like the name of the currently active AKS cluster and A...

Jun 13, 2020

Using Feature Flags with Azure App Configuration

Using Feature Flags with Azure App Configuration

Sometimes we would like to test a new feature of an application. Or we would like to disable code junks because they are not fully implem...

May 16, 2020

Logging in Azure API Management

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

How to Reference Key Vault Secrets in Azure API Management

How to Reference Key Vault Secrets in Azure API Management

In an enterprise, an Azure API Management instance is often shared by many teams and many developers. The developers may all have access ...

Feb 05, 2021