Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Removed Grants #245

Merged
merged 2 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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