Skip to content

[datadog_dashboard_json] bugfix for template_variables and notify_list #2951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dashashifrina
Copy link
Contributor

Fix unnecessary diffs for template_variables and notify_list in dashboard_json resource

Description

When using the datadog_dashboard_json resource, Terraform would show unnecessary diffs during plan/apply when template_variables or notify_list fields were not explicitly defined in the configuration. This was happening because Terraform was treating an undefined field differently from a field set to null.

Changes

Modified the prepResource function to:

  • Remove template_variables from state comparison when it's null or undefined
  • Remove notify_list from state comparison when it's null or undefined
  • Only sort notify_list when it contains actual values

Testing

To verify this fix:

  1. Create a dashboard_json resource without explicitly defining template_variables or notify_list:
resource "datadog_dashboard_json" "test" {
 dashboard = <<EOF
{
   "title":"Ordered Layout Dashboard",
   "description":"Created using the Datadog provider in Terraform",
   "layout_type": "ordered",
   "widgets": [],
}
EOF
  1. Run terraform apply to create the dashboard

  2. Run terraform plan - you should see no changes detected. Previously, this would show:

Terraform will perform the following actions:

  # datadog_dashboard_json.timeseries will be updated in-place
  ~ resource "datadog_dashboard_json" "test" {
      ~ dashboard               = jsonencode(
          ~ {
              - notify_list        = null
              - template_variables = null
                # (6 unchanged attributes hidden)
            }
        )
        id                      = "wcu-vpm-pye"
        # (2 unchanged attributes hidden)
    }

@dashashifrina dashashifrina changed the title incident-36868 [datadog_dashboard_json] bugfix for template_variables and notify_list Apr 3, 2025
if notifyList == nil {
delete(attrMap, "notify_list")
} else if notifyListSlice, ok := notifyList.([]interface{}); ok {
// handle `notify_list` order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This should only be done if notifyList is defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant