[fix][GOV] Update Read() method to update state with permissions provisioned only via terraform #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.