Skip to content

Commit

Permalink
fix: Role deletion doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjoehnk committed Dec 4, 2019
1 parent b05cf64 commit fe1757f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions mssql/resource_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func resourceRoleRead(d *schema.ResourceData, m interface{}) error {
err := row.Scan(&name)
if err == sql.ErrNoRows {
return nil
}else if err != nil {
} else if err != nil {
return err
}
if err := d.Set("name", name); err != nil {
Expand All @@ -70,8 +70,15 @@ func resourceRoleUpdate(d *schema.ResourceData, m interface{}) error {

func resourceRoleDelete(d *schema.ResourceData, m interface{}) error {
db := m.(*sql.DB)
name := d.Id()
_, err := db.Query(fmt.Sprintf("DROP USER %s", name))
row := db.QueryRow(fmt.Sprintf("SELECT name FROM master.sys.server_principals WHERE principal_id = %s", d.Id()))
var name string
err := row.Scan(&name)
if err != nil {
return err
}
dropUserQuery := fmt.Sprintf("DROP USER %s", name)
print(dropUserQuery)
_, err = db.Query(dropUserQuery)
if err != nil {
return err
}
Expand Down

0 comments on commit fe1757f

Please sign in to comment.