From fe1757f3de334d1b09a47efebffee351eb592da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20J=C3=B6hnk?= Date: Wed, 4 Dec 2019 20:28:12 +0100 Subject: [PATCH] fix: Role deletion doesn't work --- mssql/resource_role.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mssql/resource_role.go b/mssql/resource_role.go index b8ad895..9269a23 100644 --- a/mssql/resource_role.go +++ b/mssql/resource_role.go @@ -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 { @@ -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 }