Skip to content

fix(schema): resolve configuration drift in device group, alert rule, escalation chain#132

Open
ryanmat wants to merge 2 commits into
logicmonitor:masterfrom
ryanmat:fix/configuration-drift-multiple-resources
Open

fix(schema): resolve configuration drift in device group, alert rule, escalation chain#132
ryanmat wants to merge 2 commits into
logicmonitor:masterfrom
ryanmat:fix/configuration-drift-multiple-resources

Conversation

@ryanmat
Copy link
Copy Markdown

@ryanmat ryanmat commented Apr 2, 2026

Summary

  • Add DiffSuppressFunc to NameAndValue value field to handle LM API masking sensitive properties as ********** — eliminates perpetual diff on password/token properties
  • Add Computed: true to device group extra field so API-returned cloud account data does not cause perpetual deletion plans
  • Add Computed: true to custom_properties in device_group, device, collector, and collector_group resource schemas so server-injected properties do not cause ordering drift
  • Normalize nil escalating_chain to empty map in alert rule state to prevent null vs empty map drift on every plan
  • Add bounds check on escalation chain stages to prevent index out-of-bounds panic when Stages slice is empty

Fixes #53, #57, #85, #92, #115, #124

Files Changed

  • logicmonitor/schemata/name_and_value_schema.go — DiffSuppressFunc on value field
  • logicmonitor/schemata/device_group_schema.go — Computed on extra + custom_properties
  • logicmonitor/schemata/device_schema.go — Computed on custom_properties
  • logicmonitor/schemata/collector_schema.go — Computed on custom_properties
  • logicmonitor/schemata/collector_group_schema.go — Computed on custom_properties
  • logicmonitor/schemata/alert_rule_schema.go — nil guard on escalating_chain
  • logicmonitor/schemata/chain_schema.go — bounds check on Stages
  • logicmonitor/schemata/drift_fixes_test.go — unit tests (10 tests, 17 cases)

Testing

  • Unit tests: go test ./logicmonitor/schemata/ -v (all 17 cases pass)
  • Live portal validation: tested against a live LogicMonitor portal (lmryanmatuszewski) using Terraform 1.14.8 with dev_overrides
    • Device group 1870: terraform import + terraform plan = 0 changes (extra block and custom_properties clean)
    • Alert rule 3: terraform import + terraform plan = 0 changes (escalating_chain nil drift resolved)
    • Plan status: "no_changes" confirmed via structured JSON output

Cross-cutting root cause

The provider is auto-generated by go-swagger. The generated schema code lacks:

  1. DiffSuppressFunc for masked/sensitive values
  2. Computed: true on server-managed fields
  3. Nil-to-empty-map normalization for TypeMap fields
  4. Bounds checking on nested slice access

These are common patterns in hand-maintained Terraform providers that the generator does not produce.

ryanmat added 2 commits April 2, 2026 01:13
… escalation chain

- Add DiffSuppressFunc to NameAndValue value field to handle LM API
  masking sensitive properties as "**********" (fixes logicmonitor#85, logicmonitor#124)
- Add Computed: true to device group extra field so API-returned cloud
  account data does not cause perpetual deletion plans (fixes logicmonitor#57)
- Add Computed: true to custom_properties in device_group, device,
  collector, and collector_group resource schemas so server-injected
  properties do not cause ordering drift (fixes logicmonitor#53, logicmonitor#115)
- Normalize nil escalating_chain to empty map in alert rule state to
  prevent null vs empty map drift on every plan (fixes logicmonitor#92)
- Add bounds check on escalation chain stages to prevent index
  out-of-bounds panic when Stages slice is empty
- Test DiffSuppressFunc on NameAndValue value field with 6 cases:
  masked old value, non-masked values, empty values, reverse mask
- Test device group extra field has Computed: true
- Test custom_properties has Computed: true across all 4 resource schemas
- Test escalating_chain nil normalization to empty map in alert rule
- Test chain stages bounds check with empty, nil, and populated stages
- Test chain SubResourceData handles nil input gracefully
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.

Provider can not handle change in order of custom properties

1 participant