Skip to content

Commit 5d68602

Browse files
committed
Refactor module; use custom provider
1 parent 23e6817 commit 5d68602

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

postgresql/resource_postgresql_default_privileges.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func resourcePostgreSQLDefaultPrivileges() *schema.Resource {
3535
},
3636
"owner": {
3737
Type: schema.TypeString,
38-
Required: true,
38+
Optional: true,
3939
ForceNew: true,
4040
Description: "Target role for which to alter default privileges.",
4141
},
@@ -141,21 +141,23 @@ func resourcePostgreSQLDefaultPrivilegesCreate(db *DBConnection, d *schema.Resou
141141
}
142142

143143
// Needed in order to set the owner of the db if the connection user is not a superuser
144-
if err := withRolesGranted(txn, []string{owner}, func() error {
145-
146-
// Revoke all privileges before granting otherwise reducing privileges will not work.
147-
// We just have to revoke them in the same transaction so role will not lose its privileges
148-
// between revoke and grant.
149-
if err = revokeRoleDefaultPrivileges(txn, d); err != nil {
150-
return err
151-
}
152-
153-
if err = grantRoleDefaultPrivileges(txn, d); err != nil {
144+
if owner != "" {
145+
if err := withRolesGranted(txn, []string{owner}, func() error {
146+
147+
// Revoke all privileges before granting otherwise reducing privileges will not work.
148+
// We just have to revoke them in the same transaction so role will not lose its privileges
149+
// between revoke and grant.
150+
if err = revokeRoleDefaultPrivileges(txn, d); err != nil {
151+
return err
152+
}
153+
154+
if err = grantRoleDefaultPrivileges(txn, d); err != nil {
155+
return err
156+
}
157+
return nil
158+
}); err != nil {
154159
return err
155160
}
156-
return nil
157-
}); err != nil {
158-
return err
159161
}
160162

161163
if err := txn.Commit(); err != nil {

0 commit comments

Comments
 (0)