diff --git a/builtin/providers/postgresql/resource_postgresql_role.go b/builtin/providers/postgresql/resource_postgresql_role.go index 3ac0b8a94..370d98f03 100644 --- a/builtin/providers/postgresql/resource_postgresql_role.go +++ b/builtin/providers/postgresql/resource_postgresql_role.go @@ -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) } diff --git a/builtin/providers/postgresql/resource_postgresql_role_test.go b/builtin/providers/postgresql/resource_postgresql_role_test.go index 30f8a9f35..4954e1ba2 100644 --- a/builtin/providers/postgresql/resource_postgresql_role_test.go +++ b/builtin/providers/postgresql/resource_postgresql_role_test.go @@ -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 +} +`