Skip to content

Commit

Permalink
fix: Allow setting local_context_data
Browse files Browse the repository at this point in the history
fixes #59
  • Loading branch information
amhn committed Apr 24, 2022
1 parent 8a75449 commit 5ba20c6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 50 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/smutel/go-netbox v3.0.0+incompatible
github.com/smutel/go-netbox v3.0.1+incompatible
github.com/spf13/afero v1.8.2 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/vmihailenco/tagparser v0.1.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ github.com/smutel/go-netbox v2.11.0+incompatible h1:ADb7xHCQd6nOyNRZDD1CzYOqKarG
github.com/smutel/go-netbox v2.11.0+incompatible/go.mod h1:UlNOimilX5qQkyVvFaDgajexiCRjVqzh1i0r9kQfr+M=
github.com/smutel/go-netbox v3.0.0+incompatible h1:Jx8yGdB+BYBqi46bn/VNY5qBGzAtmQ9Z2E66YMmwyRI=
github.com/smutel/go-netbox v3.0.0+incompatible/go.mod h1:UlNOimilX5qQkyVvFaDgajexiCRjVqzh1i0r9kQfr+M=
github.com/smutel/go-netbox v3.0.1+incompatible h1:g/A7Hce+PPwYjbHLJrNHx7jhobB6n/VPJNkP/NiykOU=
github.com/smutel/go-netbox v3.0.1+incompatible/go.mod h1:UlNOimilX5qQkyVvFaDgajexiCRjVqzh1i0r9kQfr+M=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo=
Expand Down
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
2 changes: 1 addition & 1 deletion vendor/github.com/smutel/go-netbox/netbox/models/device.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ github.com/opentracing/opentracing-go/log
github.com/posener/complete
github.com/posener/complete/cmd
github.com/posener/complete/cmd/install
# github.com/smutel/go-netbox v3.0.0+incompatible
# github.com/smutel/go-netbox v3.0.1+incompatible
## explicit
github.com/smutel/go-netbox/netbox/client
github.com/smutel/go-netbox/netbox/client/circuits
Expand Down

0 comments on commit 5ba20c6

Please sign in to comment.