Skip to content

fix(sso): use TypeSet for team_ids to prevent ordering diffs#730

Merged
tembleking merged 3 commits into
masterfrom
fix/sso-group-mapping-team-ids-ordering
May 5, 2026
Merged

fix(sso): use TypeSet for team_ids to prevent ordering diffs#730
tembleking merged 3 commits into
masterfrom
fix/sso-group-mapping-team-ids-ordering

Conversation

@tembleking
Copy link
Copy Markdown
Member

@tembleking tembleking commented May 5, 2026

API returns team_ids in arbitrary order. Since team_ids was TypeList (order-sensitive), customers see persistent diffs on every plan/apply even when nothing changed.

Change team_ids from TypeList to TypeSet with a state upgrader (v0→v1) for transparent migration. Existing state upgrades automatically on next refresh, no destroy/recreate.

API returns team_ids in arbitrary order. Since team_ids is a TypeList
(order-sensitive), this caused persistent diffs on every plan/apply.

Sort a copy of TeamIDs before writing to state in the Read path.
Backwards compatible: existing state normalizes on next refresh.
Also fixes the same issue in the deprecated sysdig_group_mapping.
Copilot AI review requested due to automatic review settings May 5, 2026 14:57
@tembleking tembleking requested a review from a team as a code owner May 5, 2026 14:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses persistent (“phantom”) Terraform diffs caused by the Sysdig API returning team_ids in arbitrary order while the provider schema models team_ids as an order-sensitive TypeList. It normalizes ordering in the Read/flatten path so state is stable across refreshes, and adds/updates tests to catch regressions.

Changes:

  • Sort a copy of team_ids before writing it into Terraform state for sysdig_sso_group_mapping.
  • Apply the same state-normalization behavior to the deprecated sysdig_group_mapping resource.
  • Add a unit test for the sorting behavior and enhance the acceptance test to assert “no-op” plans.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
sysdig/resource_sysdig_sso_group_mapping.go Sorts team_ids before setting team_map in state to prevent order-driven diffs.
sysdig/resource_sysdig_sso_group_mapping_unit_test.go Adds a unit test asserting team_ids are sorted when flattened into state.
sysdig/resource_sysdig_sso_group_mapping_test.go Updates acceptance coverage to validate stable plans and expands team_ids scenario to multiple teams.
sysdig/resource_sysdig_group_mapping.go Applies the same team_ids sorting normalization to the deprecated resource’s Read/flatten path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sysdig/resource_sysdig_sso_group_mapping.go Outdated
Comment thread sysdig/resource_sysdig_sso_group_mapping_test.go
Comment thread sysdig/resource_sysdig_group_mapping.go
tembleking added 2 commits May 5, 2026 17:16
team_ids is an unordered collection but was defined as TypeList,
which compares element-by-element. API returns IDs in arbitrary
order causing phantom diffs on every plan/apply.

Change team_ids from TypeList to TypeSet with a state upgrader
(v0→v1) for transparent migration. Existing customer state
upgrades automatically on next refresh with no destroy/recreate.

Reverts sort-in-Read approach from previous commit as it causes
perpetual diffs when config order differs from sorted order.
Test only verified SDK converts []int to Set, not our code.
Integration test with PlanOnly step covers the actual bug.
Copilot AI review requested due to automatic review settings May 5, 2026 15:21
@tembleking tembleking changed the title fix(sso): sort team_ids in Read to prevent phantom diffs fix(sso): use TypeSet for team_ids to prevent ordering diffs May 5, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

sysdig/resource_sysdig_sso_group_mapping.go:104

  • The PR description says this is a Read-path normalization with no schema changes, but this change switches team_ids from schema.TypeList to schema.TypeSet. That is a behavioral/schema change (dedup + order-insensitive) and can be breaking for users who relied on ordering. Either update the PR description/changelog accordingly, or keep TypeList and sort a copy of the API-returned IDs before calling d.Set in Read (as described). Also, the description mentions applying the same fix to deprecated sysdig_group_mapping, but that resource still defines team_ids as a TypeList.
						"team_ids": {
							Type:     schema.TypeSet,
							Optional: true,
							Elem: &schema.Schema{
								Type: schema.TypeInt,
							},
						},

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sysdig/resource_sysdig_sso_group_mapping.go
@tembleking tembleking enabled auto-merge May 5, 2026 15:33
@tembleking tembleking added this pull request to the merge queue May 5, 2026
@tembleking tembleking merged commit 0d7373b into master May 5, 2026
184 checks passed
@tembleking tembleking deleted the fix/sso-group-mapping-team-ids-ordering branch May 5, 2026 15:37
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.

3 participants