Merge pull request #11169 from hashicorp/b-11161
Follow up to #11161 to fix `connection_limit` updates to a ROLE.
This commit is contained in:
commit
cb8d7bf8bc
|
@ -484,7 +484,7 @@ func setRoleConnLimit(conn *sql.DB, d *schema.ResourceData) error {
|
||||||
|
|
||||||
connLimit := d.Get(roleConnLimitAttr).(int)
|
connLimit := d.Get(roleConnLimitAttr).(int)
|
||||||
roleName := d.Get(roleNameAttr).(string)
|
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 {
|
if _, err := conn.Query(query); err != nil {
|
||||||
return errwrap.Wrapf("Error updating role CONNECTION LIMIT: {{err}}", err)
|
return errwrap.Wrapf("Error updating role CONNECTION LIMIT: {{err}}", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,6 @@ func TestAccPostgresqlRole_Basic(t *testing.T) {
|
||||||
Config: testAccPostgresqlRoleConfig,
|
Config: testAccPostgresqlRoleConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckPostgresqlRoleExists("postgresql_role.myrole2", "true"),
|
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", "name", "testing_role_with_defaults"),
|
||||||
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "superuser", "false"),
|
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "superuser", "false"),
|
||||||
resource.TestCheckResourceAttr("postgresql_role.role_with_defaults", "create_database", "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 {
|
func testAccCheckPostgresqlRoleDestroy(s *terraform.State) error {
|
||||||
client := testAccProvider.Meta().(*Client)
|
client := testAccProvider.Meta().(*Client)
|
||||||
|
|
||||||
|
@ -161,3 +183,18 @@ resource "postgresql_role" "role_with_defaults" {
|
||||||
valid_until = "infinity"
|
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
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue