@@ -310,6 +310,10 @@ func resourcePostgreSQLRoleCreate(d *schema.ResourceData, meta interface{}) erro
310310 return err
311311 }
312312
313+ if err = setRoleLogStatement (txn , d ); err != nil {
314+ return err
315+ }
316+
313317 if err = txn .Commit (); err != nil {
314318 return errwrap .Wrapf ("could not commit transaction: {{err}}" , err )
315319 }
@@ -464,6 +468,7 @@ func resourcePostgreSQLRoleReadImpl(c *Client, d *schema.ResourceData) error {
464468 d .Set (roleReplicationAttr , roleBypassRLS )
465469 d .Set (roleRolesAttr , pgArrayToSet (roleRoles ))
466470 d .Set (roleSearchPathAttr , readSearchPath (roleConfig ))
471+ d .Set (roleLogStatementAttr , readLogStatement (roleConfig , d .Get (roleLogStatementAttr ).(string )))
467472
468473 statementTimeout , err := readStatementTimeout (roleConfig )
469474 if err != nil {
@@ -496,6 +501,19 @@ func readSearchPath(roleConfig pq.ByteaArray) []string {
496501 return nil
497502}
498503
504+ // readLogStatement searches for a log_statement entry in the rolconfig array.
505+ // In case no such value is present, it returns empty.
506+ func readLogStatement (roleConfig pq.ByteaArray , defaultValue string ) string {
507+ for _ , v := range roleConfig {
508+ config := string (v )
509+ if strings .HasPrefix (config , roleLogStatementAttr ) {
510+ var result = strings .TrimPrefix (config , roleLogStatementAttr + "=" )
511+ return result
512+ }
513+ }
514+ return defaultValue
515+ }
516+
499517// readStatementTimeout searches for a statement_timeout entry in the rolconfig array.
500518// In case no such value is present, it returns nil.
501519func readStatementTimeout (roleConfig pq.ByteaArray ) (int , error ) {
@@ -615,6 +633,10 @@ func resourcePostgreSQLRoleUpdate(d *schema.ResourceData, meta interface{}) erro
615633 return err
616634 }
617635
636+ if err := setRoleLogStatement (txn , d ); err != nil {
637+ return err
638+ }
639+
618640 if err := setRoleReplication (txn , d ); err != nil {
619641 return err
620642 }
@@ -812,7 +834,7 @@ func setRoleLogStatement(txn *sql.Tx, d *schema.ResourceData) error {
812834 level := d .Get (roleLogStatementAttr ).(string )
813835
814836 roleName := d .Get (roleNameAttr ).(string )
815- sql := fmt .Sprintf ("ALTER ROLE %s SET log_statement TO %s" , pq .QuoteIdentifier (roleName ), level )
837+ sql := fmt .Sprintf ("ALTER ROLE %s SET log_statement TO %s" , pq .QuoteIdentifier (roleName ), pq . QuoteIdentifier ( level ) )
816838 if _ , err := txn .Exec (sql ); err != nil {
817839 return errwrap .Wrapf ("Error updating role log_statement: {{err}}" , err )
818840 }
0 commit comments