Skip to content

Commit

Permalink
resolved the update issue
Browse files Browse the repository at this point in the history
  • Loading branch information
girishramnani-crest committed Aug 10, 2017
1 parent 7fb8093 commit 7c8bf4e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions vsphere/resource_vsphere_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/vmware/govmomi"
"github.com/vmware/govmomi/license"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
"golang.org/x/net/context"
)
Expand Down Expand Up @@ -155,7 +156,12 @@ func resourceVSphereLicenseUpdate(d *schema.ResourceData, meta interface{}) erro
if err != nil {
return err
}
_, err = manager.Update(context.TODO(), keyC, mapdata)
for key, value := range mapdata {
err := UpdateLabel(context.TODO(), manager, keyC, key, value)
if err != nil {
return err
}
}
if err != nil {
return err
}
Expand Down Expand Up @@ -189,7 +195,7 @@ func labelsToMap(labels interface{}) (map[string]string, error) {
labelList := labels.([]interface{})
for _, label := range labelList {
labelMap := label.(map[string]interface{})
finalLabels[labelMap["key"].(string)] = finalLabels[labelMap["value"].(string)]
finalLabels[labelMap["key"].(string)] = labelMap["value"].(string)
}
log.Println("[G]", finalLabels)

Expand Down Expand Up @@ -218,3 +224,16 @@ func isKeyPresent(key string, manager *license.Manager) bool {

return false
}

// UpdateLabel provides a wrapper around the UpdateLabel data objects
func UpdateLabel(ctx context.Context, m *license.Manager, licenseKey string, key string, val string) error {
req := types.UpdateLicenseLabel{
This: m.Reference(),
LicenseKey: licenseKey,
LabelKey: key,
LabelValue: val,
}

_, err := methods.UpdateLicenseLabel(ctx, m.Client(), &req)
return err
}

0 comments on commit 7c8bf4e

Please sign in to comment.