Skip to content

Conversation

AbhishekSumo
Copy link
Collaborator

@AbhishekSumo AbhishekSumo commented Jul 31, 2025

Issue

  • The Sumo Logic Roles V2 API omits selectionType for default roles.
  • In the provider Read function:
    • When the API omits the field, json.Unmarshal assigns the Go zero value ("") to SelectionType.
    • The provider calls d.Set("selection_type", roleV2.SelectionType) with that empty string.
    • The Terraform SDK interprets empty string for an optional TypeString as unset and stores null in state.
  • On the next terraform apply:
    • d.Get("selection_type") returns "" (SDK converts null → "").
    • The provider sends "" to the backend.
    • The backend’s selectionTypeToAvroSelectionType throws a scala.MatchError for empty string.

Root Cause

  • omitempty only affects JSON encoding, not decoding.
  • When the API omits selectionType, Go’s json.Unmarshal sets it to the zero value "".
  • Terraform interprets "" as unset for optional attributes and stores null.
  • On update, the provider sends "" to the API instead of a valid value.

Fix

  1. Normalize in Read:
  • When SelectionType == "", default it to "All" before d.Set.
  • Prevents Terraform from storing null and avoids perpetual diffs.
  1. Force valid value in Update:
  • Before calling the API, if SelectionType == "", set it to "All".
  • Ensures a valid value is always sent and avoids MatchError.

@AbhishekSumo AbhishekSumo requested a review from a team as a code owner July 31, 2025 03:37
Copy link

⚠️ Warning: Please update CHANGELOG.md with your changes.

@AbhishekSumo AbhishekSumo requested review from ssharma-sumologic and removed request for a team July 31, 2025 03:49
@AbhishekSumo AbhishekSumo changed the title SUMO-266317: Fixing bug SUMO-266317: Fix selectionType handling for Role V2 to avoid MatchError Jul 31, 2025
Copy link
Collaborator

@ssharma-sumologic ssharma-sumologic left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@atishya-22 atishya-22 left a comment

Choose a reason for hiding this comment

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

Can we add test for this in resource_sumologic_role_v2_test.go

Copy link

github-actions bot commented Aug 4, 2025

⚠️ Warning: Please update CHANGELOG.md with your changes.

Copy link

github-actions bot commented Aug 5, 2025

⚠️ Warning: Please update CHANGELOG.md with your changes.

Copy link

github-actions bot commented Aug 5, 2025

⚠️ Warning: Please update CHANGELOG.md with your changes.

@AbhishekSumo AbhishekSumo merged commit f150b63 into master Aug 6, 2025
9 checks passed
@AbhishekSumo AbhishekSumo deleted the absingh-266317 branch August 6, 2025 04:20
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.

4 participants