How to Use Azure Dashboard JSON to Create a Dashboard via Terraform?

Jyoti Teli (BLR GSS) 20 Reputation points
2025-01-08T05:36:44.14+00:00

I have exported a JSON file of a dashboard that I created on the Azure Portal. Now, I want to use this JSON file to deploy the same dashboard through Terraform.

Can someone guide me on how to achieve this? Specifically:

  1. Which Terraform resource should I use for creating a dashboard?
  2. How do I reference the JSON file in the Terraform script?
  3. Are there any specific configurations or steps to follow to ensure the deployment works successfully?

It would be great if someone could provide an example Terraform script or point me to relevant documentation.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,411 questions
{count} votes

Accepted answer
  1. Ashok Gandhi Kotnana 1,855 Reputation points Microsoft Vendor
    2025-01-08T09:00:50.2133333+00:00

    Hi @Jyoti Teli (BLR GSS) ,

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    Please find the below 3 questions that has been answered and do let me know if you face any challenges here.

    1.Which Terraform resource should I use for creating a dashboard?

    A) This Terraform code automates the creation of multiple Azure dashboards by using a list of inputs that specify each dashboard's name, JSON template, and variables. It sets the location, resource group, and tags for each dashboard and dynamically generates their configurations based on the provided templates.

    Refer: https://github.com/kumarvna/terraform-azurerm-dashboard/blob/main/main.tf

    https://www.techielass.com/deploy-an-azure-dashboard-using-terraform/#:~:text=The%20%22json_file_path%22%20is%20where%20you,your%20dashboard%20will%20be%20deployed.Deploy an Azure Dashboard using Terraform

    TerraformEdit development language

    resource "azurerm_portal_dashboard" "main" {
      for_each             = { for k in var.dashboards : k.name => k }
      name                 = format("%s", each.key)
      resource_group_name  = local.resource_group_name
      location             = local.location
      dashboard_properties = templatefile(each.value.json_file_path, each.value.variables)
      tags                 = merge({ "ResourceName" = format("%s", each.key) }, var.tags, )
    }
    

    2.How do I reference the JSON file in the Terraform script?

    A) Below if the path this should point to the location where the JSON dashboard was downloaded. The path below refers to the current directory, please select your file path

    json_file_path = "./test_dashboard.json"

    TerraformEdit development language

      dashboards = [
        {
          name           = "my-cool-dashboard"
          json_file_path = "./test_dashboard.json"
          variables = {
            "title" = "example-dashboard"
          }
        }
      ]
    

    Refer below: This provides the exact path to the configuration, which you can use to reference the JSON file in your Terraform code

    https://github.com/kumarvna/terraform-azurerm-dashboard/blob/main/examples/complete/main.tf

    3.Are there any specific configurations or steps to follow to ensure the deployment works successfully?

    A)In the exported JSON template, you need to delete the second line, which corresponds to the 'properties' section

    1. Refer: https://www.techielass.com/deploy-an-azure-dashboard-using-terraform/#:~:text=The%20%22json_file_path%22%20is%20where%20you,your%20dashboard%20will%20be%20deployed.User's image

    Remove below highlighted lines in your Json export script it is typically will be in the end of the script

    User's image

    Save the changes to the file.  

    let us know if you have any further queries. I’m happy to assist you further.   

     If the comment is helpful, please click "Upvote it"

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.