Skip to content

Commit 02129af

Browse files
author
Thomas D. Spear
committed
Add support for routine in postgresql_default_privileges
Signed-off-by: Thomas D. Spear <[email protected]>
1 parent 25fbd1c commit 02129af

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

postgresql/resource_postgresql_default_privileges.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ func resourcePostgreSQLDefaultPrivileges() *schema.Resource {
5353
"table",
5454
"sequence",
5555
"function",
56+
"routine",
5657
"type",
5758
"schema",
5859
}, false),
59-
Description: "The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema)",
60+
Description: "The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, routine, type, schema)",
6061
},
6162
"privileges": {
6263
Type: schema.TypeSet,
@@ -87,6 +88,13 @@ func resourcePostgreSQLDefaultPrivilegesRead(db *DBConnection, d *schema.Resourc
8788
)
8889
}
8990

91+
if objectType == "routine" && !db.featureSupported(featureRoutine) {
92+
return fmt.Errorf(
93+
"object type ROUTINE is not supported for this Postgres version (%s)",
94+
db.version,
95+
)
96+
}
97+
9098
exists, err := checkRoleDBSchemaExists(db, d)
9199
if err != nil {
92100
return err
@@ -119,6 +127,13 @@ func resourcePostgreSQLDefaultPrivilegesCreate(db *DBConnection, d *schema.Resou
119127
return fmt.Errorf("cannot specify `schema` when `object_type` is `schema`")
120128
}
121129

130+
if objectType == "routine" && !db.featureSupported(featureRoutine) {
131+
return fmt.Errorf(
132+
"object type ROUTINE is not supported for this Postgres version (%s)",
133+
db.version,
134+
)
135+
}
136+
122137
if d.Get("with_grant_option").(bool) && strings.ToLower(d.Get("role").(string)) == "public" {
123138
return fmt.Errorf("with_grant_option cannot be true for role 'public'")
124139
}

website/docs/r/postgresql_default_privileges.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ resource "postgresql_default_privileges" "read_only_tables" {
3232
* `database` - (Required) The database to grant default privileges for this role.
3333
* `owner` - (Required) Specifies the role that creates objects for which the default privileges will be applied.
3434
* `schema` - (Optional) The database schema to set default privileges for this role.
35-
* `object_type` - (Required) The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, type, schema).
35+
* `object_type` - (Required) The PostgreSQL object type to set the default privileges on (one of: table, sequence, function, routine, type, schema).
3636
* `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.
3737

3838

0 commit comments

Comments
 (0)