@@ -310,6 +310,10 @@ func resourcePostgreSQLRoleCreate(d *schema.ResourceData, meta interface{}) erro
310
310
return err
311
311
}
312
312
313
+ if err = setRoleLogStatement (txn , d ); err != nil {
314
+ return err
315
+ }
316
+
313
317
if err = txn .Commit (); err != nil {
314
318
return errwrap .Wrapf ("could not commit transaction: {{err}}" , err )
315
319
}
@@ -464,6 +468,7 @@ func resourcePostgreSQLRoleReadImpl(c *Client, d *schema.ResourceData) error {
464
468
d .Set (roleReplicationAttr , roleBypassRLS )
465
469
d .Set (roleRolesAttr , pgArrayToSet (roleRoles ))
466
470
d .Set (roleSearchPathAttr , readSearchPath (roleConfig ))
471
+ d .Set (roleLogStatementAttr , readLogStatement (roleConfig , d .Get (roleLogStatementAttr ).(string )))
467
472
468
473
statementTimeout , err := readStatementTimeout (roleConfig )
469
474
if err != nil {
@@ -496,6 +501,19 @@ func readSearchPath(roleConfig pq.ByteaArray) []string {
496
501
return nil
497
502
}
498
503
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
+
499
517
// readStatementTimeout searches for a statement_timeout entry in the rolconfig array.
500
518
// In case no such value is present, it returns nil.
501
519
func readStatementTimeout (roleConfig pq.ByteaArray ) (int , error ) {
@@ -615,6 +633,10 @@ func resourcePostgreSQLRoleUpdate(d *schema.ResourceData, meta interface{}) erro
615
633
return err
616
634
}
617
635
636
+ if err := setRoleLogStatement (txn , d ); err != nil {
637
+ return err
638
+ }
639
+
618
640
if err := setRoleReplication (txn , d ); err != nil {
619
641
return err
620
642
}
@@ -812,7 +834,7 @@ func setRoleLogStatement(txn *sql.Tx, d *schema.ResourceData) error {
812
834
level := d .Get (roleLogStatementAttr ).(string )
813
835
814
836
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 ) )
816
838
if _ , err := txn .Exec (sql ); err != nil {
817
839
return errwrap .Wrapf ("Error updating role log_statement: {{err}}" , err )
818
840
}
0 commit comments