dynatrace-oss / terraform-provider-dynatrace

Apache License 2.0
68 stars 31 forks source link

encountering non-empty plans when deploying json dashboards #504

Open amsanmie opened 1 month ago

amsanmie commented 1 month ago

Describe the bug Terraform keeps trying to update the contents of the json dashboards even if there are no changes in the code. My observation is that the content it keeps trying to add is part of the dashboard json code but it's not stored in the state file thereby causing the non-empty plans.

To Reproduce Steps to reproduce the behavior: Use any of the preset dashboards from this link https://github.com/Dynatrace/snippets/tree/master/product/dashboarding/aws-metric-streaming and attach the json file to the dashboard resource similar to below

resource "dynatrace_json_dashboard" "dashboard" { for_each = local.dashboard_files_classic

contents = each.value link_id = dynatrace_json_dashboard_base.dashboard_base[each.key].id

provider = dynatrace.dashboard }

dynatrace version 1.59.1

Expected behavior Terraform plan only shows changes when changes are made in the code as it should be.

Screenshots screenshot showing the code

Screenshot 2024-07-23 at 16 47 19

Screenshot showing the terraform plan

Screenshot 2024-07-23 at 16 46 32

Screenshot showing the state file, which indicate the dashboard filter being part of the code but not part of the state file

Screenshot 2024-07-23 at 16 48 05

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

Dynatrace-Reinhard-Pilz commented 1 month ago

Hello @amsanmie,

You're experiencing a well known limitation we're facing with Terraform when applying Dashboards.

Unfortunately the JSON code you're getting when exporting Dashboards as JSON via WebUI and the JSON Code that's provided via REST API aren't aligned in multiple ways.

In most cases it is simply about default values vs omitting an attribute. And within these cases it is usually about additional, optional attributes that CAN get omitted.

The only bullet proof way to ensure non-empty plans at the moment is to gradually align the local JSON code within your Terraform Module until the plan remains empty.

I'm going to keep this ticket open, however. After trying out a couple of the JSON files that are available through the link you've provided I'm sure we can reduce the possibility of non-empty plans to a bare minimum - simply by suppressing the diff for a couple of edge cases we've not been aware of yet.

We will keep you posted here about the progress.

best regards, Reinhard