Skip to content

Fix component type update deleting unmanaged relationships#646

Merged
saditya370 merged 3 commits intoOpsLevel:mainfrom
saditya370:fix/reconcile-relationships-on-update
Apr 21, 2026
Merged

Fix component type update deleting unmanaged relationships#646
saditya370 merged 3 commits intoOpsLevel:mainfrom
saditya370:fix/reconcile-relationships-on-update

Conversation

@saditya370
Copy link
Copy Markdown
Collaborator

Summary

  • Bug: Updating a component type (e.g. adding properties or changing description) would silently delete all relationship definitions, even when the user didn't touch the relationships block. Reported by LandSure on provider v1.9.0 (GitLab #14723).
  • Root cause: reconcileRelationships() ran unconditionally on every update and deleted any API-side relationship not found in the current plan. A nil/empty plan meant "delete everything."
  • Fix: Added a guard to skip reconciliation when neither plan nor prior state has relationships. Changed the deletion loop to only delete relationships that were previously in Terraform state but removed from the new plan. Relationships created outside Terraform (e.g. via UI) are now left untouched.

Test plan

  • TestReconcileRelationships_NilPlanNilState — no relationships in plan or state → no deletes
  • TestReconcileRelationships_NilPlanWithState — user removes relationships block → deletes only what was in state
  • TestReconcileRelationships_PlanMatchesAPI — no changes → updates only, no deletes
  • TestReconcileRelationships_EmptyPlanNilState — empty map with nil state → no deletes
  • TestReconcileRelationships_APIHasExtraNotInState — UI-created relationships → left untouched
  • TestReconcileRelationships_RemoveOneKeepOne — partial removal → deletes one, updates other
  • TestReconcileRelationships_AddNewRelationship — new relationship added → creates it, no deletes
  • TestReconcileRelationships_RemoveAllFromState — explicit removal of all → deletes all from state
  • TestReconcileRelationships_StateHasOneAPIHasExtraKeepBoth — TF manages one, UI created another → only updates TF-managed one
  • All existing tests pass (go test ./opslevel/ — 12/12)
  • Full build clean (go build ./...)

Comment thread opslevel/resource_opslevel_component_type.go Outdated
Comment thread opslevel/resource_opslevel_component_type.go Outdated
@andrewstillv15 andrewstillv15 self-requested a review April 20, 2026 16:18
@andrewstillv15
Copy link
Copy Markdown
Contributor

We have to add a changie before this gets merged

@saditya370 saditya370 merged commit 5d8128e into OpsLevel:main Apr 21, 2026
4 checks passed
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.

2 participants