Today we are going to be adding another article to our Terraform for Azure series. To see how to setup a basic Azure App Service in Terraform check out our article here. This week we are going to be looking at one of the biggest benefits you can add to your app service, Azure Application Insights.

Application Insights is an application performance management service. There is a ton you can do with Application Insights but some of the highlights are exception/logging, performance metrics, and session counts. For a full list of the possibilities check it out the full run down in the Microsoft documentation.

Let’s go – Creating Application Insights with Terraform

So the code to add an Application Insight to your app service is extremely easy. Let’s dump it here and then break it down:

resource "azurerm_application_insights" "api" {
  name                = "example-application_insights"
  location            = azurerm_resource_group.example.location
  resource_group_name =
  application_type    = "web"

For the rest of the terraform you can either look at the article I mentioned earlier, or I’ll post the full terraform at the end of this article. The terraform above is pretty basic but let’s break it down:

  • name – this is simply what the name of the application insight instance will be when viewed in Azure
  • location – this is the geographic location where we want the instance to be located. We are just piggy backing on the same one defined for our azurerm_resource_group
  • resource_group_name – this will be the name of the resource group. We covered this in the last article, or you can see the definition at the end of this article, we just reference it here.
  • application_type – there are a number of valid application types, we are doing a web service. To see the full list check out the terraform documentation for azurerm_application_insights.

Running the Terraform

Now we simply need to run the terraform with the addition above. To get the full run down on how to execute Terraform for Azure check out our first article here. Running a terraform plan should show the following:


Developer Command Prompt

If all looks well, go ahead and run a terraform apply. Once that is done, we can go over to the Azure Portal and see our new Application Insight. You should be able to type Application insight into the search bar, and see the new name in the list of available instances:


Application Insights

It’s really that simple! Now that we have it, we can use this same code to deploy the same setup multiple times. We will always have Application Insights included to leverage its logging, exceptions, and performance statistics. We highly recommend everyone take a look at the Microsoft documentation on Application Insights. It deserves an article or blog of its own.

We still have only scratched the surface of what we can do with Terraform. Logging is an important piece that we want to make sure is baked in at the beginning, but we still have only scratched the surface of what we can do with Terraform. Next we hope to dive into setting up multiple environments, and start looking at some automated deployment options to tie everything together. Expect more to come!

The JBS Quick Launch Lab

1/2 Day Assessment

Quantify what it will take to implement your next big idea!

Our intensive 1/2 day session will deliver tangible timelines, costs, high-level requirements, and recommend architectures that will work best. Let JBS show you why over 20 years of experience matters.

Get Your Assessment