Deploy Azure Workbooks with Terraform

Terraform can be used to deploy Workbooks to Azure to help you monitor your environment. In this example, I use the very useful Orphaned Resources Workbook which can be used to spot disconnected resources such as unattached disks or public IPs which could be adding to your Azure bill unnecessarily.

The Terraform code below could also be used with the JSON template of any other workbook, and should be straightforward to modify and drop into your own code repository.

To deploy this resource start by downloading the workbook from Github and placing it in your repository. This will be the file orphaned.resources.workbook referenced in the Terraform code.

 1###################### Orphaned Resources Workbook ###################################################
 2# Deploy the Orphaned Resources Workbook from JSON file
 3
 4# Generate a random UUID for the workbook name. The resource name needs the ID, a display_name
 5# parameter in the workbook resource will provide the friendly name.
 6resource "random_uuid" "orphaned_workbook_id" {
 7}
 8# Create the Workbook from the JSON file
 9resource "azurerm_application_insights_workbook" "orphaned" {
10    data_json           = file("${path.module}/orphaned.resources.workbook")
11    name                = random_uuid.orphaned_workbook_id.result
12    resource_group_name = "rg-workbooks"            # Replace with your resource group name
13    location            = "uksouth"                 # Replace with your location
14    display_name        = "Orphaned Resources Workbook"
15}