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
[x] 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)
Related issues
Relates to #549, potentially sets the state to support a policy attachment feature in the future
Checklists
Development
[x] Lint rules pass locally
[x] 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.)
[x] 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
Description of the change
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
Related issues
Checklists
Development
false
.)go generate
to make sure the docs are up to dateCode review