Tuesday, April 11, 2023

 The following is a Terraform module to create an Azure dashboard for a specific user supplied content and query. It quickly deploys a panel for a query on a supported metric that can be authored in KQL externally and specified here via a URL to the query in the dashboard definitions. Dashboard panel and visualizations can be created from the Shared dashboards URL: https://portal.azure.com/#view/HubsExtension/BrowseResource/resourceType/Microsoft.Portal%2Fdashboards. 

 

provider "azurerm" { 

  features {} 

} 

 

data "azurerm_subscription" "current" {} 

 

resource "azurerm_resource_group" example_rg { 

  name     = var.resource_group 

  location = "Central US" 

} 

 

resource "azurerm_portal_dashboard" example_dashboard_name { 

  name                = var.dashboard_name 

  resource_group_name = azurerm_resource_group.example_rg.name 

  location            = azurerm_resource_group.example_rg.location 

  tags = { 

    source = "terraform" 

  } 

  dashboard_properties = <<DASH 

{ 

   "lenses": { 

        "0": { 

            "order": 0, 

            "parts": { 

                "0": { 

                    "position": { 

                        "x": 0, 

                        "y": 0, 

                        "rowSpan": 5, 

                        "colSpan": 5 

                    }, 

                    "metadata": { 

                        "inputs": [], 

                        "type": "Extension/HubsExtension/PartType/MarkdownPart", 

                        "settings": { 

                            "content": { 

                                "settings": { 

                                    "content": "${var.query_content}", 

                                    "subtitle": "", 

                                    "title": "${var.dashboard_title}" 

                                } 

                            } 

                        } 

                    } 

                }, 

                "1": { 

                    "position": { 

                        "x": 5, 

                        "y": 0, 

                        "rowSpan": 5, 

                        "colSpan": 6 

                    }, 

                    "metadata": { 

                        "inputs": [], 

                        "type": "Extension/Microsoft_Azure_Monitoring/PartType/MetricsChartPart", 

                        "settings": { 

                            "content": { 

                                "settings": { 

                                    "title": "Important Information", 

                                    "subtitle": "", 

                                    "src": "${var.query_link}", 

                                    "autoplay": true 

                                } 

                            } 

                        } 

                    } 

                } 

            } 

        } 

    }, 

    "metadata": { 

        "owner": "${var.dashboard_owner_email}", 

        "model": { 

            "timeRange": { 

                "value": { 

                    "relative": { 

                        "duration": 24, 

                        "timeUnit": 1 

                    } 

                }, 

                "type": "MsPortalFx.Composition.Configuration.ValueTypes.TimeRange" 

            }, 

            "filterLocale": { 

                "value": "en-us" 

            }, 

            "filters": { 

                "value": { 

                    "MsPortalFx_TimeRange": { 

                        "model": { 

                            "format": "utc", 

                            "granularity": "auto", 

                            "relative": "24h" 

                        }, 

                        "displayCache": { 

                            "name": "UTC Time", 

                            "value": "Past 24 hours" 

                        }, 

                        "filteredPartIds": [ 

                            "StartboardPart-UnboundPart-ae44fef5-76b8-46b0-86f0-2b3f47bad1c7" 

                        ] 

                    } 

                } 

            } 

        } 

    } 

} 

DASH 

} 

 

As with all Terraform modules, this can be run via the following Terraform commands: 

terraform init 

terraform plan 

terraform apply 

and the command terraform destroy can be run when this resource is no longer needed. 

No comments:

Post a Comment