Skip to content

widgets = file(...) causes non-idempotent behavior due to string mismatch #33

Open
@daihiraoka

Description

@daihiraoka

Summary

The current documentation shows using widgets = file("widgets.json"), which successfully creates a dashboard in Instana, but causes Terraform to detect changes on every plan/apply, due to mismatched formatting of string contents.

Details

Using file() loads the raw JSON string with indentation and newline characters. Since the Instana provider compares widget definitions as raw strings instead of structured data, Terraform detects a difference on every execution, even when there are no actual changes.

Example warning from terraform apply:

[WARN] Provider "registry.terraform.io/instana/instana" produced an invalid plan for instana_custom_dashboard.example, but we are tolerating it because it is using the legacy plugin SDK.

The following problems may be the cause of any confusing errors from downstream operations:

.widgets: planned value ... does not match config value ...

This indicates that while the provider currently tolerates this mismatch, it may lead to breaking behavior in future versions of Terraform or the provider itself.

Recommended Fix

Update the documentation and usage examples to promote the following safer pattern:

locals {
  widgets = jsondecode(file("${path.module}/widgets.json"))
}

resource "instana_custom_dashboard" "example" {
  title = "My Dashboard"

  access_rule {
    access_type   = "READ_WRITE"
    relation_type = "USER"
    related_id    = var.instana_user_id
  }

  widgets = jsonencode(local.widgets)
}

This ensures the contents are parsed as structured JSON objects and re-encoded in a consistent format, preserving idempotency and eliminating unnecessary diffs.

Benefit

  • Prevents unnecessary changes on every plan/apply
  • Ensures consistency across environments
  • Avoids future compatibility issues with Terraform and the provider

Thanks for maintaining this provider!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions