From f3a34cc4327f9c288c17a31648f590845b8bdef3 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Wed, 19 Nov 2025 17:30:14 +0000 Subject: [PATCH] Add a shared dashboard module We would like to setup a dashboard on the Azure portal for our different environments on the Invite team. This would allow repos to pass in a template file as the dashboard_properties, e.g: ``` dashboard_properties = templatefile("dashboard-template.tpl", { environment = var.environment sub_id = var.hub_subscription_id } ) ``` https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/portal_dashboard --- infrastructure/modules/dashboard/README.md | 4 ++ infrastructure/modules/dashboard/main.tf | 9 ++++ infrastructure/modules/dashboard/tfdocs.md | 50 +++++++++++++++++++ infrastructure/modules/dashboard/variables.tf | 30 +++++++++++ .../modules/shared-config/output.tf | 1 + 5 files changed, 94 insertions(+) create mode 100644 infrastructure/modules/dashboard/README.md create mode 100644 infrastructure/modules/dashboard/main.tf create mode 100644 infrastructure/modules/dashboard/tfdocs.md create mode 100644 infrastructure/modules/dashboard/variables.tf diff --git a/infrastructure/modules/dashboard/README.md b/infrastructure/modules/dashboard/README.md new file mode 100644 index 00000000..4797c022 --- /dev/null +++ b/infrastructure/modules/dashboard/README.md @@ -0,0 +1,4 @@ +# app-insights + +## Terraform documentation +For the list of inputs, outputs, resources... check the [terraform module documentation](tfdocs.md). diff --git a/infrastructure/modules/dashboard/main.tf b/infrastructure/modules/dashboard/main.tf new file mode 100644 index 00000000..745cda95 --- /dev/null +++ b/infrastructure/modules/dashboard/main.tf @@ -0,0 +1,9 @@ +resource "azurerm_portal_dashboard" "dashboard" { + + name = var.name + location = var.location + resource_group_name = var.resource_group_name + tags = var.tags + + dashboard_properties = var.dashboard_properties +} diff --git a/infrastructure/modules/dashboard/tfdocs.md b/infrastructure/modules/dashboard/tfdocs.md new file mode 100644 index 00000000..847580d8 --- /dev/null +++ b/infrastructure/modules/dashboard/tfdocs.md @@ -0,0 +1,50 @@ +# Module documentation + +## Required Inputs + +The following input variables are required: + +### [location](#input\_location) + +Description: The location/region where the dashboard is created. + +Type: `string` + +### [name](#input\_name) + +Description: Is the dashboard workspace name. + +Type: `string` + +### [resource\_group\_name](#input\_resource\_group\_name) + +Description: The name of the resource group in which the Dashboard is created. Changing this forces a new resource to be created. + +Type: `string` + +## Optional Inputs + +The following input variables are optional (have default values): + +### [dashboard\_properties](#input\_dashboard\_properties) + +Description: JSON data representing dashboard body. See above for details on how to obtain this from the Portal. + +Type: `string` + +Default: `{}` + +### [tags](#input\_tags) + +Description: A mapping of tags to assign to the resource. + +Type: `map(string)` + +Default: `{}` + + +## Resources + +The following resources are used by this module: + +- [azurerm_portal_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/portal_dashboard) (resource) diff --git a/infrastructure/modules/dashboard/variables.tf b/infrastructure/modules/dashboard/variables.tf new file mode 100644 index 00000000..15a7d1b1 --- /dev/null +++ b/infrastructure/modules/dashboard/variables.tf @@ -0,0 +1,30 @@ +variable "location" { + type = string + description = "The location/region where the dashboard is created." +} + +variable "name" { + description = "Is the dashboard workspace name." + type = string + validation { + condition = can(regex("^[a-zA-Z0-9][a-zA-Z0-9-_]{0,253}[a-zA-Z0-9]$", var.name)) + error_message = "The Dashboard name must be between 1 and 255 characters, start and end with an alphanumeric character, and can contain alphanumeric characters, hyphens, periods, and underscores (but not at the start or end)." + } +} + +variable "resource_group_name" { + type = string + description = "The name of the resource group in which the Dashboard is created. Changing this forces a new resource to be created." +} + +variable "tags" { + type = map(string) + default = {} + description = "A mapping of tags to assign to the resource." +} + +variable "dashboard_properties" { + type = string + default = {} + description = "JSON data representing dashboard body. See above for details on how to obtain this from the Portal." +} diff --git a/infrastructure/modules/shared-config/output.tf b/infrastructure/modules/shared-config/output.tf index 024ff766..fb1536d4 100644 --- a/infrastructure/modules/shared-config/output.tf +++ b/infrastructure/modules/shared-config/output.tf @@ -64,6 +64,7 @@ locals { container-app-environment = lower("CAE-${var.env}-${var.location_map[var.location]}-${var.application}") connection = lower("CON-${var.env}-${var.location_map[var.location]}-${var.application}") custom-image = lower("IMAGE-${var.env}-${var.location_map[var.location]}") + dashboard = lower("DASH-${var.env}-${var.location_map[var.location]}-${var.application}") dev-center = lower("DEVC-${var.env}-${var.location_map[var.location]}") dev-center-project = lower("prj-${var.env}-${var.location_map[var.location]}") dns-zone = lower("${var.application}.${var.env}.net")