-
Notifications
You must be signed in to change notification settings - Fork 3
[fix][GOV] Update Read() method to update state with permissions provisioned only via terraform #48
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
Conversation
|
@Keshavrajsinghal This is a suggestion i haven't fully tested out, but i think that if you add another provider to the acctest.go file, you could use it to send API request without affecting the state of the main provider, thus being able to add changes to the retool instance and also being able to record and replay them. |
|
I merged this with main and modified the tests. The tests are less comprehensive than your original but will work with replay. I also tested this with a universal access permission group on a local instance (see the terraform output below) and this seems to be working well. I'm going to accept, but @Keshavrajsinghal can you also review the changes I made prior to merging? |
Keshavrajsinghal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
The
Read()method inpermissions/resource.gowas fetching all permissions for a subject from the API and storing them in Terraform state, causing unmanaged (UI-created / API created) permissions to be deleted when removing the Terraform resource. We now build a map of managed permissions from the existing state and filter API responses to only include those permissions that Terraform originally created.During import operations however, the state is initially empty, which would cause the managed permissions map to be empty and filter out all permissions from the API response. To handle this, we refactored the API fetching logic into a reusable
fetchPermissionsForSubject()helper method and updated ImportState() to populate permissions beforeRead()is automatically called, ensuring the managed permissions map is correctly initialized with the imported baseline.Tests
Added two new acceptance tests:
TestAccPermissions_ManagedDeletionverifies that removing a Terraform-managed permission resource doesn't delete unmanaged permissions created via the UI or API, andTestAccPermissions_ReadOnlyManagedconfirms that the Read() method only tracks managed permissions in state while leaving unmanaged ones intact. Both tests use direct API calls to create unmanaged permissions and verify they persist after Terraform operations.Note: These tests have been commented out because they rely on direct API calls that do not get recorded. As a result, they fail CD pipelines as they try to bypass the recorder and hit the RETOOL_HOST which is a dummy host set to recorded.retool.dev. They pass with real hosts as tested locally.