hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.62k stars 4.66k forks source link

azurerm_portal_dashboard is semi-broken because it does not support the current apiVersion "2022-12-01-preview" #27944

Open simonfelding opened 3 weeks ago

simonfelding commented 3 weeks ago

Is there an existing issue for this?

Community Note

Terraform Version

1.9.7

AzureRM Provider Version

4.9.0

Affected Resource(s)/Data Source(s)

azurerm_portal_dashboard

Terraform Configuration Files

resource "azurerm_portal_dashboard" "dashboard" {
    name = "overview"
    resource_group_name = var.resource_group
    location = var.location
    dashboard_properties = jsonencode(jsondecode(file("./dashboard.json")).properties)
}

Debug Output/Panic Output

╷
│ Error: parsing JSON: json: cannot unmarshal array into Go struct field DashboardProperties.lenses of type map[string]dashboard.DashboardLens
│
│   with azurerm_portal_dashboard.overview,
│   on dashboard.tf line 5, in resource "azurerm_portal_dashboard" "overview":
│    5:     dashboard_properties = jsonencode(jsondecode(file("./dashboard.json")).properties)
│
╵

Expected Behaviour

I expected that I could export a portal dashboard as json, and then load it as a string with the azurerm_portal_dashboard resource.

(PS: i also think it's a bit silly that I have to extract the properties block)

Actual Behaviour

The azurerm_portal_dashboard resource expects a map but gets an array.

This changed between the 2019 and 2020 api versions.

see: https://learn.microsoft.com/en-us/azure/templates/microsoft.portal/2020-09-01-preview/dashboards?pivots=deployment-language-bicep https://learn.microsoft.com/en-us/azure/templates/microsoft.portal/2019-01-01-preview/dashboards?pivots=deployment-language-bicep

Steps to Reproduce

  1. download a dashboard as dashboard.json (as per the documentation).
  2. terraform validate

Important Factoids

No response

References

example of how the json used to look: https://github.com/hashicorp/terraform-provider-azurerm/issues/9104

yoshigev commented 22 hours ago

Looks like a duplicate of https://github.com/hashicorp/terraform-provider-azurerm/issues/27117 (except that that issue is tagged as "documentation" for some reason).