Skip to content

Commit

Permalink
added check for deleting the key
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani-crest committed Aug 10, 2017
1 parent 7c8bf4e commit 7eac7c5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions vsphere/resource_vsphere_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
var (
// ErrNoSuchKeyFound is an error primarily thrown by the Read method of the resource.
// The error doesnt display the key itself for security reasons.
ErrNoSuchKeyFound = errors.New("The key was not found")
ErrNoSuchKeyFound = errors.New("The key was not found")
ErrKeyCannotBeDeleted = errors.New("The key wasn't deleted")
)

func resourceVSphereLicense() *schema.Resource {
Expand Down Expand Up @@ -179,10 +180,20 @@ func resourceVSphereLicenseDelete(d *schema.ResourceData, meta interface{}) erro
manager := license.NewManager(client.Client)

if key := d.Get("license_key").(string); isKeyPresent(key, manager) {
d.SetId("")

err := manager.Remove(context.TODO(), key)
log.Println("[G] Error removing the key", err)
return err

if err != nil {
return err

}

// if the key is still present
if isKeyPresent(key, manager) {
return ErrKeyCannotBeDeleted
}
d.SetId("")
return nil
}
return ErrNoSuchKeyFound

Expand Down

0 comments on commit 7eac7c5

Please # to comment.