diff --git a/internal/resources/grafana/resource_service_account_permission.go b/internal/resources/grafana/resource_service_account_permission.go index 84872b025..453d20860 100644 --- a/internal/resources/grafana/resource_service_account_permission.go +++ b/internal/resources/grafana/resource_service_account_permission.go @@ -119,7 +119,7 @@ func getServiceAccountPermissions(ctx context.Context, d *schema.ResourceData, m return nil, diag.FromErr(err) } - saPermissions, err := client.GetServiceAccountPermissions(id) + saPermissions, err := client.ListServiceAccountResourcePermissions(id) if err, shouldReturn := common.CheckReadError("service account permissions", d, err); shouldReturn { return nil, err } @@ -163,12 +163,12 @@ func updateServiceAccountPermissions(client *gapi.Client, idStr string, from, to } } - permissionList := gapi.ServiceAccountPermissionItems{} + var permissionList []gapi.SetResourcePermissionItem // Iterate over permissions from the configuration (the desired permission setup) for _, p := range listOrSet(to) { permission := p.(map[string]interface{}) - permissionItem := gapi.ServiceAccountPermissionItem{} + permissionItem := gapi.SetResourcePermissionItem{} _, teamIDStr := SplitOrgResourceID(permission["team_id"].(string)) teamID, _ := strconv.ParseInt(teamIDStr, 10, 64) _, userIDStr := SplitOrgResourceID(permission["user_id"].(string)) @@ -194,24 +194,25 @@ func updateServiceAccountPermissions(client *gapi.Client, idStr string, from, to permissionItem.UserID = userID } permissionItem.Permission = permission["permission"].(string) - permissionList.Permissions = append(permissionList.Permissions, &permissionItem) + permissionList = append(permissionList, permissionItem) } // Remove the permissions that are in the state but not in the config for teamID := range oldTeamPerms { - permissionList.Permissions = append(permissionList.Permissions, &gapi.ServiceAccountPermissionItem{ + permissionList = append(permissionList, gapi.SetResourcePermissionItem{ TeamID: teamID, Permission: "", }) } for userID := range oldUserPerms { - permissionList.Permissions = append(permissionList.Permissions, &gapi.ServiceAccountPermissionItem{ + permissionList = append(permissionList, gapi.SetResourcePermissionItem{ UserID: userID, Permission: "", }) } - return client.UpdateServiceAccountPermissions(id, &permissionList) + _, err = client.SetServiceAccountResourcePermissions(id, gapi.SetResourcePermissionsBody{Permissions: permissionList}) + return err } func listOrSet(v interface{}) []interface{} { diff --git a/internal/resources/grafana/resource_service_account_permission_test.go b/internal/resources/grafana/resource_service_account_permission_test.go index c2dea02a6..168227f6d 100644 --- a/internal/resources/grafana/resource_service_account_permission_test.go +++ b/internal/resources/grafana/resource_service_account_permission_test.go @@ -20,7 +20,7 @@ func TestAccServiceAccountPermission(t *testing.T) { name := acctest.RandString(10) - var saPermission gapi.ServiceAccountPermission + var saPermission gapi.ResourcePermission resource.ParallelTest(t, resource.TestCase{ ProviderFactories: testutils.ProviderFactories, CheckDestroy: testAccServiceAccountPermissionsCheckDestroy(saPermission.ID), @@ -42,7 +42,7 @@ func TestAccServiceAccountPermission_inOrg(t *testing.T) { name := acctest.RandString(10) - var saPermission gapi.ServiceAccountPermission + var saPermission gapi.ResourcePermission resource.ParallelTest(t, resource.TestCase{ ProviderFactories: testutils.ProviderFactories, CheckDestroy: testAccServiceAccountPermissionsCheckDestroy(saPermission.ID), @@ -61,7 +61,7 @@ func TestAccServiceAccountPermission_inOrg(t *testing.T) { }) } -func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAccountPermission) resource.TestCheckFunc { +func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ResourcePermission) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[rn] if !ok { @@ -76,7 +76,7 @@ func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAcc } client := testutils.Provider.Meta().(*common.Client).GrafanaAPI.WithOrgID(orgID) - perms, err := client.GetServiceAccountPermissions(saID) + perms, err := client.ListServiceAccountResourcePermissions(saID) if err != nil { return fmt.Errorf("error getting service account permissions: %s", err) } @@ -92,7 +92,7 @@ func testServiceAccountPermissionsCheckExists(rn string, saPerm *gapi.ServiceAcc func testAccServiceAccountPermissionsCheckDestroy(id int64) resource.TestCheckFunc { return func(s *terraform.State) error { client := testutils.Provider.Meta().(*common.Client).GrafanaAPI - saPerms, err := client.GetServiceAccountPermissions(id) + saPerms, err := client.ListServiceAccountResourcePermissions(id) if err != nil { return err }