@@ -24,6 +24,7 @@ const (
24
24
roleEncryptedPassAttr = "encrypted_password"
25
25
roleInheritAttr = "inherit"
26
26
roleLoginAttr = "login"
27
+ roleLogStatementAttr = "log_statement"
27
28
roleNameAttr = "name"
28
29
rolePasswordAttr = "password"
29
30
roleReplicationAttr = "replication"
@@ -39,6 +40,13 @@ const (
39
40
roleDepEncryptedAttr = "encrypted"
40
41
)
41
42
43
+ var allowedLogStatementOpts = []string {
44
+ "none" ,
45
+ "ddl" ,
46
+ "mod" ,
47
+ "all" ,
48
+ }
49
+
42
50
func resourcePostgreSQLRole () * schema.Resource {
43
51
return & schema.Resource {
44
52
Create : resourcePostgreSQLRoleCreate ,
@@ -131,6 +139,13 @@ func resourcePostgreSQLRole() *schema.Resource {
131
139
Default : false ,
132
140
Description : "Determine whether a role is allowed to log in" ,
133
141
},
142
+ roleLogStatementAttr : {
143
+ Type : schema .TypeString ,
144
+ Optional : true ,
145
+ Default : "none" ,
146
+ ValidateFunc : validation .StringInSlice (allowedLogStatementOpts , false ),
147
+ Description : "Sets the log level for SQL statements" ,
148
+ },
134
149
roleReplicationAttr : {
135
150
Type : schema .TypeBool ,
136
151
Optional : true ,
@@ -789,6 +804,22 @@ func setRoleLogin(txn *sql.Tx, d *schema.ResourceData) error {
789
804
return nil
790
805
}
791
806
807
+ func setRoleLogStatement (txn * sql.Tx , d * schema.ResourceData ) error {
808
+ if ! d .HasChange (roleLogStatementAttr ) {
809
+ return nil
810
+ }
811
+
812
+ level := d .Get (roleLogStatementAttr ).(string )
813
+
814
+ roleName := d .Get (roleNameAttr ).(string )
815
+ sql := fmt .Sprintf ("ALTER ROLE %s SET log_statement TO %s" , pq .QuoteIdentifier (roleName ), level )
816
+ if _ , err := txn .Exec (sql ); err != nil {
817
+ return errwrap .Wrapf ("Error updating role log_statement: {{err}}" , err )
818
+ }
819
+
820
+ return nil
821
+ }
822
+
792
823
func setRoleReplication (txn * sql.Tx , d * schema.ResourceData ) error {
793
824
if ! d .HasChange (roleReplicationAttr ) {
794
825
return nil
0 commit comments