Skip to content

Oncall integration labels order creates perma-diff #2169

@trnubo

Description

@trnubo

Terraform Version

OpenTofu v1.8.8

Terraform Grafana Provider Version

provider registry.opentofu.org/grafana/grafana v3.25.0

Grafana Version

Grafana Cloud

Affected Resource(s)

  • grafana_oncall_integration

Terraform Configuration Files

data "grafana_oncall_label" "source" {
  key = "source"
  value = "test"
}

data "grafana_oncall_label" "severity" {
  key = "severity"
  value = "warning"
}

data "grafana_oncall_label" "customer" {
  key = "customer"
  value = "acme"
}

resource "grafana_oncall_integration" "test_integration" {
  provider = grafana.oncall
  name     = "TEST INTEGRATION"
  type     = "webhook"

  default_route {
  }

  labels = [
    data.grafana_oncall_label.source,
    data.grafana_oncall_label.severity,
    data.grafana_oncall_label.customer,
  ]
}

Expected Behavior

Since the API does not treat the order of labels as significant the terraform provider should not either.

Changing the order of labels in terraform should not result in any diff.

Actual Behavior

The terraform provider seems to treat the order as significant resulting in a perma-diff when the order of labels is changed in terraform.

Steps to Reproduce

  1. Apply the test terraform config above
  2. Reorder the labels, eg
labels = [
  data.grafana_oncall_label.source,
  data.grafana_oncall_label.customer,
  data.grafana_oncall_label.severity,
]
  1. Apply the reordered labels
  2. Perform another terraform plan to see that there is still a diff. Example output below.

Important Factoids

No response

References

Oncall integration labels added to the provider in #2125

When managing Oncall integration labels via Terraform the order of labels is treated a significant by the provider however it seems that the order is not significant to the API. This can result in perma-diff when every plan and apply results in the same diff. The apply does not seem to actually make any difference to the API. If the order is not significant to the API there should not have been any diff in the first place.

We were managing the labels via the UI however since label support was added to the terraform provider we migrated our config to terraform for consistency (although there is still missing functionality for managing integrations via terraform #1581).

Example of the perma-diff

  # grafana_oncall_integration.test_integration will be updated in-place
  ~ resource "grafana_oncall_integration" "test_integration" {
        id     = "CIAEFVAYPK4QV"
      ~ labels = [
            {
                "id"    = "source"
                "key"   = "source"
                "value" = "test"
            },
          - {
              - "id"    = "severity"
              - "key"   = "severity"
              - "value" = "warning"
            },
            {
                "id"    = "customer"
                "key"   = "customer"
                "value" = "acme"
            },
          + {
              + "id"    = "severity"
              + "key"   = "severity"
              + "value" = "warning"
            },
        ]
        name   = "TEST INTEGRATION"
        # (2 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Work around

It is possible to work around this issue by removing the labels from an integration and re-adding them however the difference in behavior between the API and provider should still be considered a bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions