See how Adaptiv can transform your business. Schedule a kickoff call today

Enhancing Operational Visibility: Leveraging Azure Workbooks - Part 3a

  • Technical

This is an addendum to Part 3 of a three-part blog post that describes how to use the power of Log Analytics Workbooks to display tracking data that can be filtered, sorted, and even exported to Excel. 

This post shows the differences when deploying using Terraform. 

See Part 1 – Display Work Orders in a Grid with Filters for the first post. 

See Part 2 – Display a Related Records Grid for the second post. 

See Part 3 – Automate Deployment for the third post. 

Terraform Deployment 

Using Terraform for deploying workbooks is a little different to using Bicep. Terraform syntax is quite different, and the deployment is recorded in a state file. 

Get Log Analytics Workspace 

First, a reference to the existing Log Analytics workspace is required.

// Get Log Analytics workspace
data "azurerm_log_analytics_workspace" "log_analytics_workspace-wkbk" {
  provider            = azurerm
  name                = "log-fs-monitoring-aue-dev"
  resource_group_name = "re-shared-aue-dev"
}   

Prepare Gallery File 

The Gallery file saved from the portal (see previous blog article) needs to have some values updated in a similar way to Bicep. The main string to replace is the resource ID. Add other replacements if you have other environment-specific values in the Gallery. 

The approach used is to do this using Terraform is a local variable in the variables.tf file.

// Log Analytics Workspace workbook – Work Order

locals {

   updated_gallery_json = replace(file("./LogAnalyticsWorkbooks/wkbk-workorder/wkbk-myworkbook.gallery.json"), "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/rg-shared-dev-aue/providers/microsoft.operationalinsights/workspaces/log-fs-monitoring-dev-aue", data.azurerm_log_analytics_workspace.log_analytics_workspace-wkbk.id)

   workbook_id_workorders = "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" # This is the globally unique GUID of this workbook
}

The JSON is used in the azurerm_application_insights_workbook resource template against the data_json property.

The following Terraform code is used for deploying the workbook.

A unique and consistent identifier is needed for the workbook name to facilitate future updates. The example below demonstrates how to achieve this using the uuidv5() function.

# Create/update the workbook.
# The gallery is updated in the local variable in variables.tf.
# Generate an unchanging UUID for the workbook name using the uuidv5() function. This uses a unique ID and the workbook display name, which contains the environment abbreviation, to ensure uniqueness.
resource "azurerm_application_insights_workbook" "log_analytics_workspace-wkbk-workorder" {
   name = lower(uuidv5(local.workbook_id_workorders, "${local.workbook_id_workorders}Work Order Workbook"))
   resource_group_name = data.azurerm_resource_group.rg-monitoring-wkbk.name
   location = data.azurerm_resource_group.rg-monitoring-wkbk.location
   source_id = lower(data.azurerm_log_analytics_workspace.log_analytics_workspace-wkbk.id) # Terraform bug workaround - need to use lower()
   display_name = "Work Order Workbook"
   data_json = local.updated_gallery_json
}

Summary

This concludes (again) the series of blog posts that demonstrate a small but useful feature set of workbooks.

Read Azure Workbooks[1] to discover the full potential of workbooks.

Ready to elevate your data transit security and enjoy peace of mind?

Click here to schedule a free, no-obligation consultation with our Adaptiv experts. Let us guide you through a tailored solution that's just right for your unique needs.

Your journey to robust, reliable, and rapid application security begins now!

Talk To Us