Search code examples
f#azure-application-insightsazure-rm-templateinfrastructure-as-code

How to bring complex Application Insights to a Farmer deployment?


I got interested in Farmer and decided to try it out in my project. I managed to replace most of the ARM template with Farmer.

However, there are Application Insights left, as I have quite a complicated setup there, including some alerts, scheduled query rules and so on. Whereas everything that Farmer currently supports for AI is just name, IP masking and sample percentage.

How can I plug in AI setup into the Farmer so that I don't reject Farmer just because of that part? My service looks like this:

let webApp = webApp {
    name appName
    service_plan_name servicePlanName
    sku WebApp.Sku.B1
    always_on
    ...
}

Solution

  • So webApp setup has a builder keyword for this, link_to_unmanaged_app_insights:

    Instructs Farmer to link this webapp to an existing app insights instance that is externally managed, rather than creating a new one.

    However there are no examples and only one test using it, so after some experimenting, this is what proved to work:

    1. Keep having AI setup in ARM in the source code, e.g. arm-template-ai.json.
    2. Note the AI resource Id.
    3. Use the aforementioned keyword in the F# app setup:
    let webApp = webApp {
        name appName
        service_plan_name servicePlanName
        sku WebApp.Sku.B1
        always_on
        link_to_unmanaged_app_insights (ResourceId.create appInsightsName)
    }
    
    1. In the release pipeline, first deploy AI from the AI ARM template in the source code.
    2. Then deploy all other resources from the ARM template generated by Farmer.

    An example how it can look in Azure DevOps:

    Pipeline