Skip to content

Commit

Permalink
fix: Allow setting local_context_data
Browse files Browse the repository at this point in the history
  • Loading branch information
amhn committed Apr 17, 2022
1 parent 7da516c commit 2813aa6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions netbox/resource_netbox_virtualization_vm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package netbox

import (
"encoding/json"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -156,7 +157,6 @@ func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData,
Cluster: &clusterID,
Comments: comments,
CustomFields: &customFields,
LocalContextData: &localContextData,
Name: &name,
Status: status,
Tags: convertTagsToNestedTags(tags),
Expand All @@ -170,6 +170,14 @@ func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData,
newResource.Memory = &memory
}

if localContextData != "" {
var localContextDataMap map[string]*interface{}
if err := json.Unmarshal([]byte(localContextData), &localContextDataMap); err != nil {
return err
}
newResource.LocalContextData = localContextDataMap
}

if platformID != 0 {
newResource.Platform = &platformID
}
Expand Down Expand Up @@ -241,8 +249,12 @@ func resourceNetboxVirtualizationVMRead(d *schema.ResourceData,
return err
}

localContextDataJSON, err := json.Marshal(resource.LocalContextData)
if err != nil {
return err
}
if err = d.Set("local_context_data",
*resource.LocalContextData); err != nil {
string(localContextDataJSON)); err != nil {
return err
}

Expand Down Expand Up @@ -336,7 +348,11 @@ func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData,

if d.HasChange("local_context_data") {
localContextData := d.Get("local_context_data").(string)
params.LocalContextData = &localContextData
var localContextDataMap map[string]*interface{}
if err := json.Unmarshal([]byte(localContextData), &localContextDataMap); err != nil {
return err
}
params.LocalContextData = localContextDataMap
}

if d.HasChange("memory") {
Expand Down

0 comments on commit 2813aa6

Please sign in to comment.