Skip to content

Conversation

@Keshavrajsinghal
Copy link

@Keshavrajsinghal Keshavrajsinghal commented Oct 2, 2025

Description

The Read() method in permissions/resource.go was 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 before Read() is automatically called, ensuring the managed permissions map is correctly initialized with the imported baseline.

Tests

Added two new acceptance tests: TestAccPermissions_ManagedDeletion verifies that removing a Terraform-managed permission resource doesn't delete unmanaged permissions created via the UI or API, and TestAccPermissions_ReadOnlyManaged confirms 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.

@EhudB
Copy link
Contributor

EhudB commented Oct 10, 2025

@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.
For reading, i think you will have to implement a data_source for permissions in order to allow the recording to both validate the data returned from retool and record it

@nguyenmp nguyenmp requested a review from simplyluke October 14, 2025 21:35
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