Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert user policies from List to Set #587

Merged
merged 1 commit into from
Nov 22, 2024
Merged

Conversation

peterdeme
Copy link
Contributor

@peterdeme peterdeme commented Nov 21, 2024

Description of the change

This is essentially @bushong1 's change, plus some additional fixes. Quoting:

#577

I’ve been having some trouble with the Spacelift Terraform provider when managing user access policies. Every time I add a new policy, Terraform tries to delete and recreate some of the existing ones—even though they haven’t changed at all. It’s like it’s getting confused about what’s actually new and what’s already there.
I think the problem is with how the policy field is set up in the spacelift_user resource. Right now, it’s defined as a TypeList, which is ordered. So when I insert a new policy somewhere other than the end of the list, it shifts the order, and Terraform thinks the policies have changed.
To fix this, I think we should change policy from a TypeList to a TypeSet. Sets are unordered, so Terraform won’t care about the order of the policies anymore. Also, by adding a custom hash function that combines space_id and role, we can uniquely identify each policy.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (non-breaking change that adds documentation)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • Examples for new resources and data sources have been added
  • Default values have been documented in the description (e.g., "Dummy: (Boolean) Blah blah. Defaults to false.)
  • If the action fails that checks the documentation: Run go generate to make sure the docs are up to date

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Pull Request is no longer marked as "draft"
  • Reviewers have been assigned
  • Changes have been reviewed by at least one other engineer

@peterdeme peterdeme force-pushed the user-policy-list-to-set branch from 3a7676f to b5fcf3b Compare November 21, 2024 18:02
@peterdeme peterdeme changed the title Convert user policies fromList to Set Convert user policies from List to Set Nov 21, 2024
@peterdeme peterdeme marked this pull request as ready for review November 21, 2024 18:19
@peterdeme peterdeme requested review from adamconnelly and a team November 21, 2024 18:29
@peterdeme peterdeme merged commit 0b0d800 into main Nov 22, 2024
7 checks passed
@peterdeme peterdeme deleted the user-policy-list-to-set branch November 22, 2024 10:54
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