Skip to content

Commit

Permalink
fix: Don't display changes when vcpus does not contain .00
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed Oct 26, 2021
1 parent 04c752e commit 085050b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions netbox/resource_netbox_virtualization_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -117,6 +118,12 @@ func resourceNetboxVirtualizationVM() *schema.Resource {
ValidateFunc: validation.StringMatch(
regexp.MustCompile("^[0-9]+|[0-9]+.[0-9]+$"),
"Must be like ^[0-9]+|[0-9]+.[0-9]+$"),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == new+".00" || old == new {
return true
}
return false
},
},
},
}
Expand All @@ -141,6 +148,10 @@ func resourceNetboxVirtualizationVMCreate(d *schema.ResourceData,
tenantID := int64(d.Get("tenant_id").(int))
vcpus := d.Get("vcpus").(string)

if !strings.Contains(vcpus, ".") {
vcpus = vcpus + ".00"
}

newResource := &models.WritableVirtualMachineWithConfigContext{
Cluster: &clusterID,
Comments: comments,
Expand Down Expand Up @@ -355,6 +366,11 @@ func resourceNetboxVirtualizationVMUpdate(d *schema.ResourceData,

if d.HasChange("vcpus") {
vcpus := d.Get("vcpus").(string)

if !strings.Contains(vcpus, ".") {
vcpus = vcpus + ".00"
}

params.Vcpus = &vcpus
}

Expand Down

0 comments on commit 085050b

Please sign in to comment.