@@ -212,20 +212,52 @@ func (r *role_privilege_grantResource) Delete(ctx context.Context, req resource.
212212 return
213213 }
214214
215- id := state .EntityId .ValueString ()
216- tflog .Debug (ctx , "Deleting role_privilege_grant" , map [string ]interface {}{"id" : id })
217- err := r .client .DeleteRolePrivilegeGrant (ctx , id )
215+ // Build the revoke request using the same approach as Update
216+ roleId := state .RoleId .ValueString ()
217+ entityId := state .EntityId .ValueString ()
218+ entityKind := state .EntityKind .ValueString ()
219+ privilege := state .Privilege .ValueString ()
220+
221+ tflog .Debug (ctx , "Deleting role_privilege_grant" , map [string ]interface {}{
222+ "roleId" : roleId ,
223+ "entityId" : entityId ,
224+ "privilege" : privilege ,
225+ })
226+
227+ // Create the revoke request
228+ revokeRequest := make (map [string ]interface {})
229+ revokeRequest ["entityId" ] = entityId
230+ revokeRequest ["entityKind" ] = entityKind
231+ revokeRequest ["privilege" ] = privilege
232+ revokeRequest ["revokeAction" ] = "RemoveRoleGrant"
233+
234+ // Include optional scope fields if set
235+ if ! state .ColumnName .IsNull () && state .ColumnName .ValueString () != "" {
236+ revokeRequest ["columnName" ] = state .ColumnName .ValueString ()
237+ }
238+ if ! state .SchemaName .IsNull () && state .SchemaName .ValueString () != "" {
239+ revokeRequest ["schemaName" ] = state .SchemaName .ValueString ()
240+ }
241+ if ! state .TableName .IsNull () && state .TableName .ValueString () != "" {
242+ revokeRequest ["tableName" ] = state .TableName .ValueString ()
243+ }
244+
245+ err := r .client .RevokeRolePrivilege (ctx , roleId , revokeRequest )
218246 if err != nil {
219247 if ! client .IsNotFound (err ) {
220248 resp .Diagnostics .AddError (
221249 "Error deleting role_privilege_grant" ,
222- "Could not delete role_privilege_grant " + id + " : "+ err .Error (),
250+ "Could not delete role_privilege_grant: " + err .Error (),
223251 )
224252 return
225253 }
226254 }
227255
228- tflog .Debug (ctx , "Deleted role_privilege_grant" , map [string ]interface {}{"id" : id })
256+ tflog .Debug (ctx , "Deleted role_privilege_grant" , map [string ]interface {}{
257+ "roleId" : roleId ,
258+ "entityId" : entityId ,
259+ "privilege" : privilege ,
260+ })
229261}
230262
231263// Helper methods
@@ -300,31 +332,39 @@ func (r *role_privilege_grantResource) updateModelFromResponse(ctx context.Conte
300332 model .GrantOption = types .BoolValue (grantOption )
301333 }
302334
335+ // For optional scope fields (columnName, schemaName, tableName), preserve plan values
336+ // when the API doesn't return them. This handles the case where users specify wildcard
337+ // values like "*" that the API accepts but doesn't echo back in the response.
338+ // If the plan value is null/unknown, set to null (must be known after apply).
303339 if columnName , ok := response ["columnName" ].(string ); ok {
304340 model .ColumnName = types .StringValue (columnName )
305- } else {
341+ } else if model . ColumnName . IsNull () || model . ColumnName . IsUnknown () {
306342 model .ColumnName = types .StringNull ()
307343 }
344+ // Otherwise keep existing model value (user-specified value like "*")
308345
309346 if schemaName , ok := response ["schemaName" ].(string ); ok {
310347 model .SchemaName = types .StringValue (schemaName )
311- } else {
348+ } else if model . SchemaName . IsNull () || model . SchemaName . IsUnknown () {
312349 model .SchemaName = types .StringNull ()
313350 }
351+ // Otherwise keep existing model value (user-specified value like "*")
314352
315353 if tableName , ok := response ["tableName" ].(string ); ok {
316354 model .TableName = types .StringValue (tableName )
317- } else {
355+ } else if model . TableName . IsNull () || model . TableName . IsUnknown () {
318356 model .TableName = types .StringNull ()
319357 }
358+ // Otherwise keep existing model value (user-specified value like "*")
320359
321360 // Note: Pagination fields are not part of the model as they are handled at the framework level
322361
323362 if listAllPrivileges , ok := response ["listAllPrivileges" ].(bool ); ok {
324363 model .ListAllPrivileges = types .BoolValue (listAllPrivileges )
325- } else {
364+ } else if model . ListAllPrivileges . IsNull () || model . ListAllPrivileges . IsUnknown () {
326365 model .ListAllPrivileges = types .BoolNull ()
327366 }
367+ // Otherwise keep existing model value
328368
329369 // Note: Role privilege grants are individual operations, not list operations
330370}
0 commit comments