Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.

Commit d7918bb

Browse files
committed
init
1 parent 3e2ad5f commit d7918bb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

postgresql/resource_postgresql_role.go

+31
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
roleEncryptedPassAttr = "encrypted_password"
2525
roleInheritAttr = "inherit"
2626
roleLoginAttr = "login"
27+
roleLogStatementAttr = "log_statement"
2728
roleNameAttr = "name"
2829
rolePasswordAttr = "password"
2930
roleReplicationAttr = "replication"
@@ -39,6 +40,13 @@ const (
3940
roleDepEncryptedAttr = "encrypted"
4041
)
4142

43+
var allowedLogStatementOpts = []string{
44+
"none",
45+
"ddl",
46+
"mod",
47+
"all",
48+
}
49+
4250
func resourcePostgreSQLRole() *schema.Resource {
4351
return &schema.Resource{
4452
Create: resourcePostgreSQLRoleCreate,
@@ -131,6 +139,13 @@ func resourcePostgreSQLRole() *schema.Resource {
131139
Default: false,
132140
Description: "Determine whether a role is allowed to log in",
133141
},
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+
},
134149
roleReplicationAttr: {
135150
Type: schema.TypeBool,
136151
Optional: true,
@@ -789,6 +804,22 @@ func setRoleLogin(txn *sql.Tx, d *schema.ResourceData) error {
789804
return nil
790805
}
791806

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+
792823
func setRoleReplication(txn *sql.Tx, d *schema.ResourceData) error {
793824
if !d.HasChange(roleReplicationAttr) {
794825
return nil

0 commit comments

Comments
 (0)