Follow up to #11161 to fix `connection_limit` updates to a ROLE.

This commit is contained in:
Sean Chittenden 2017-01-11 16:24:00 -08:00
parent 864c7691b1
commit 4278c615af
No known key found for this signature in database
GPG Key ID: 4EBC9DC16C2E5E16
2 changed files with 44 additions and 7 deletions

View File

@ -484,7 +484,7 @@ func setRoleConnLimit(conn *sql.DB, d *schema.ResourceData) error {
connLimit := d.Get(roleConnLimitAttr).(int)
roleName := d.Get(roleNameAttr).(string)
query := fmt.Sprintf("ALTER ROLE %s CONNECTION LIMIT = %d", pq.QuoteIdentifier(roleName), connLimit)
query := fmt.Sprintf("ALTER ROLE %s CONNECTION LIMIT %d", pq.QuoteIdentifier(roleName), connLimit)
if _, err := conn.Query(query); err != nil {
return errwrap.Wrapf("Error updating role CONNECTION LIMIT: {{err}}", err)
}

View File

@ -19,12 +19,6 @@ func TestAccPostgresqlRole_Basic(t *testing.T) {
Config: testAccPostgresqlRoleConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlRoleExists("postgresql_role.myrole2", "true"),
resource.TestCheckResourceAttr("postgresql_role.myrole2", "name", "myrole2"),
resource.TestCheckResourceAttr("postgresql_role.myrole2", "login", "true"),
resource.TestCheckResourceAttr("postgresql_role.myrole2", "skip_drop_role", "false"),
resource.TestCheckResourceAttr("postgresql_role.myrole2", "skip_reassign_owned", "false"),
resource.TestCheckResourceAttr("postgresql_role.myrole2", "connection_limit", "-1"),
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "name", "testing_role_with_defaults"),
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "superuser", "false"),
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "create_database", "false"),
@ -44,6 +38,34 @@ func TestAccPostgresqlRole_Basic(t *testing.T) {
})
}
func TestAccPostgresqlRole_Update(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPostgresqlRoleDestroy,
Steps: []resource.TestStep{
{
Config: testAccPostgresqlRoleUpdate1Config,
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlRoleExists("postgresql_role.update_role", "true"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "name", "update_role"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "login", "true"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "connection_limit", "-1"),
),
},
{
Config: testAccPostgresqlRoleUpdate2Config,
Check: resource.ComposeTestCheckFunc(
testAccCheckPostgresqlRoleExists("postgresql_role.update_role", "true"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "name", "update_role2"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "login", "true"),
resource.TestCheckResourceAttr("postgresql_role.update_role", "connection_limit", "5"),
),
},
},
})
}
func testAccCheckPostgresqlRoleDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*Client)
@ -161,3 +183,18 @@ resource "postgresql_role" "role_with_defaults" {
valid_until = "infinity"
}
`
var testAccPostgresqlRoleUpdate1Config = `
resource "postgresql_role" "update_role" {
name = "update_role"
login = true
}
`
var testAccPostgresqlRoleUpdate2Config = `
resource "postgresql_role" "update_role" {
name = "update_role2"
login = true
connection_limit = 5
}
`