Skip to content

Add support for routines in postgresql_default_privileges #535

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion postgresql/resource_postgresql_default_privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func resourcePostgreSQLDefaultPrivileges() *schema.Resource {
"table",
"sequence",
"function",
"routine",
"type",
"schema",
}, false),
Description: "The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema)",
Description: "The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, routine, type, schema)",
},
"privileges": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -87,6 +88,13 @@ func resourcePostgreSQLDefaultPrivilegesRead(db *DBConnection, d *schema.Resourc
)
}

if objectType == "routine" && !db.featureSupported(featureRoutine) {
return fmt.Errorf(
"object type ROUTINE is not supported for this Postgres version (%s)",
db.version,
)
}

exists, err := checkRoleDBSchemaExists(db, d)
if err != nil {
return err
Expand Down Expand Up @@ -119,6 +127,13 @@ func resourcePostgreSQLDefaultPrivilegesCreate(db *DBConnection, d *schema.Resou
return fmt.Errorf("cannot specify `schema` when `object_type` is `schema`")
}

if objectType == "routine" && !db.featureSupported(featureRoutine) {
return fmt.Errorf(
"object type ROUTINE is not supported for this Postgres version (%s)",
db.version,
)
}

if d.Get("with_grant_option").(bool) && strings.ToLower(d.Get("role").(string)) == "public" {
return fmt.Errorf("with_grant_option cannot be true for role 'public'")
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/postgresql_default_privileges.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "postgresql_default_privileges" "read_only_tables" {
* `database` - (Required) The database to grant default privileges for this role.
* `owner` - (Required) Specifies the role that creates objects for which the default privileges will be applied.
* `schema` - (Optional) The database schema to set default privileges for this role.
* `object_type` - (Required) The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
* `object_type` - (Required) The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, routine, type, schema).
* `privileges` - (Required) List of privileges (e.g., SELECT, INSERT, UPDATE, DELETE) to grant on new objects created by the owner. An empty list could be provided to revoke all default privileges for this role.


Expand Down