azurermDashboard
Manages a shared dashboard in the Azure Portal.
!> Note: The azurermDashboard
resource is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the azurermPortalDashboard
resource instead.
Example Usage
import * as cdktf from "cdktf";
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
/*Terraform Variables are not always the best fit for getting inputs in the context of Terraform CDK.
You can read more about this at https://cdk.tf/variables*/
const mdContent = new cdktf.TerraformVariable(this, "md_content", {
default: "# Hello all :)",
description: "Content for the MD tile",
});
const videoLink = new cdktf.TerraformVariable(this, "video_link", {
default: "https://www.youtube.com/watch?v=......",
description: "Link to a video",
});
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
this,
"example",
{
location: "West Europe",
name: "mygroup",
}
);
const dataAzurermSubscriptionCurrent =
new azurerm.dataAzurermSubscription.DataAzurermSubscription(
this,
"current",
{}
);
new azurerm.dashboard.Dashboard(this, "my-board", {
dashboard_properties: `{
"lenses": {
"0": {
"order": 0,
"parts": {
"0": {
"position": {
"x": 0,
"y": 0,
"rowSpan": 2,
"colSpan": 3
},
"metadata": {
"inputs": [],
"type": "Extension/HubsExtension/PartType/MarkdownPart",
"settings": {
"content": {
"settings": {
"content": "\${${mdContent.value}}",
"subtitle": "",
"title": ""
}
}
}
}
},
"1": {
"position": {
"x": 5,
"y": 0,
"rowSpan": 4,
"colSpan": 6
},
"metadata": {
"inputs": [],
"type": "Extension/HubsExtension/PartType/VideoPart",
"settings": {
"content": {
"settings": {
"title": "Important Information",
"subtitle": "",
"src": "\${${videoLink.value}}",
"autoplay": true
}
}
}
}
},
"2": {
"position": {
"x": 0,
"y": 4,
"rowSpan": 4,
"colSpan": 6
},
"metadata": {
"inputs": [
{
"name": "ComponentId",
"value": "/subscriptions/\${${dataAzurermSubscriptionCurrent.subscriptionId}}/resourceGroups/myRG/providers/microsoft.insights/components/myWebApp"
}
],
"type": "Extension/AppInsightsExtension/PartType/AppMapGalPt",
"settings": {},
"asset": {
"idInputName": "ComponentId",
"type": "ApplicationInsights"
}
}
}
}
}
},
"metadata": {
"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"
]
}
}
}
}
}
}
`,
location: azurermResourceGroupExample.location,
name: "my-cool-dashboard",
resource_group_name: azurermResourceGroupExample.name,
tags: {
source: "terraform",
},
});
It is recommended to follow the steps outlined here to create a Dashboard in the Portal and extract the relevant JSON to use in this resource. From the extracted JSON, the contents of the properties: {}
object can used. Variables can be injected as needed - see above example.
Using a templateFile
data source or the templatefile
function
Since the contents of the dashboard JSON can be quite lengthy, use a template file to improve readability:
dashTpl
:
{
"lenses": {
"0": {
"order": 0,
"parts": {
"0": {
"position": {
"x": 0,
"y": 0,
"rowSpan": 2,
"colSpan": 3
},
"metadata": {
"inputs": [],
"type": "Extension/HubsExtension/PartType/MarkdownPart",
"settings": {
"content": {
"settings": {
"content": "${md_content}", // <-- note the 'var.' is dropped
"subtitle": "",
"title": ""
}
}
}
}
},
...
...
This is then referenced in the tf
file by using a templateFile
data source (terraform 0.11 or earlier), or the templatefile
function (terraform 0.12+).
mainTf
(terraform 0.11 or earlier):
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
import * as template from "./.gen/providers/template";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm, template.
For a more precise conversion please use the --provider flag in convert.*/
const dataTemplateFileDashTemplate =
new template.dataTemplateFile.DataTemplateFile(this, "dash-template", {
template: '${file("${path.module}/dash.tpl")}',
vars: [
{
md_content: "Variable content here!",
sub_id: "${data.azurerm_subscription.current.subscription_id}",
video_link: "https://www.youtube.com/watch?v=......",
},
],
});
new azurerm.dashboard.Dashboard(this, "my-board", {
dashboard_properties: dataTemplateFileDashTemplate.rendered,
location: "${azurerm_resource_group.example.location}",
name: "my-cool-dashboard",
resource_group_name: "${azurerm_resource_group.example.name}",
tags: {
source: "terraform",
},
});
mainTf
(terraform 0.12+)
/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
new azurerm.dashboard.Dashboard(this, "my-board", {
dashboard_properties:
'${templatefile("dash.tpl",\n {\n md_content = "Variable content here!",\n video_link = "https://www.youtube.com/watch?v=......",\n sub_id = data.azurerm_subscription.current.subscription_id\n })}',
location: "${azurerm_resource_group.example.location}",
name: "my-cool-dashboard",
resource_group_name: "${azurerm_resource_group.example.name}",
tags: {
source: "terraform",
},
});
Argument Reference
The following arguments are supported:
name
- (Required) Specifies the name of the Shared Dashboard. Changing this forces a new resource to be created.
-> Note: You can specify a tag with the key hiddenTitle
to set a more user-friendly title for this Dashboard.
-
resourceGroupName
- (Required) The name of the resource group in which to create the dashboard. Changing this forces a new resource to be created. -
location
- (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -
dashboardProperties
- (Optional) JSON data representing dashboard body. See above for details on how to obtain this from the Portal. -
tags
- (Optional) A mapping of tags to assign to the resource.
Attributes Reference
The following attributes are exported:
id
- The ID of the Dashboard.
Timeouts
The timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 30 minutes) Used when creating the Dashboard.update
- (Defaults to 30 minutes) Used when updating the Dashboard.read
- (Defaults to 5 minutes) Used when retrieving the Dashboard.delete
- (Defaults to 30 minutes) Used when deleting the Dashboard.
Import
Dashboards can be imported using the resourceId
, e.g.
terraform import azurerm_dashboard.my-board /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.Portal/dashboards/00000000-0000-0000-0000-000000000000
Note the URI in the above sample can be found using the Resource Explorer tool in the Azure Portal.