Skip to content

Commit

Permalink
Fix Removed Grants (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
dehume authored Jul 27, 2023
1 parent c59fcdb commit ed01ac4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/resources/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resources
import (
"context"
"fmt"
"log"
"strings"

"github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize"
Expand Down Expand Up @@ -48,7 +49,9 @@ func grantRead(ctx context.Context, d *schema.ResourceData, meta interface{}) di
privilege := d.Get("privilege").(string)

if !materialize.HasPrivilege(priviledgeMap[key.roleId], privilege) {
return diag.Errorf("%s: object does not contain privilege: %s", i, privilege)
log.Printf("[DEBUG] %s: object does not contain privilege: %s", i, privilege)
// Remove id from state
d.SetId("")
}

return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/resources/resource_grant_default_privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"strings"

"github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize"
Expand Down Expand Up @@ -71,8 +72,9 @@ func grantDefaultPrivilegeRead(ctx context.Context, d *schema.ResourceData, meta
}

if !slices.Contains(mapping[mapKey], key.privilege) {
log.Printf("[DEBUG] %s: object does not contain privilege: %s", i, key.privilege)
// Remove id from state
d.SetId("")
return diag.Errorf("%s: %s default privilege does not contain privilege %s", mapping, i, key.privilege)
}

d.SetId(i)
Expand Down
4 changes: 3 additions & 1 deletion pkg/resources/resource_grant_system_privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"strings"

"github.com/MaterializeInc/terraform-provider-materialize/pkg/materialize"
Expand Down Expand Up @@ -80,8 +81,9 @@ func grantSystemPrivilegeRead(ctx context.Context, d *schema.ResourceData, meta
mapping, _ := materialize.ParseSystemPrivileges(privileges)

if !slices.Contains(mapping[key.roleId], key.privilege) {
log.Printf("[DEBUG] %s: object does not contain privilege: %s", i, key.privilege)
// Remove id from state
d.SetId("")
return diag.Errorf("system role does contain privilege %s", key.privilege)
}

d.SetId(i)
Expand Down

0 comments on commit ed01ac4

Please sign in to comment.