From 085050bb6ee04f7892410fc37e33fbd0c184ffd4 Mon Sep 17 00:00:00 2001 From: smutel <12967891+smutel@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:04:01 +0200 Subject: [PATCH] fix: Don't display changes when vcpus does not contain .00 --- netbox/resource_netbox_virtualization_vm.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/netbox/resource_netbox_virtualization_vm.go b/netbox/resource_netbox_virtualization_vm.go index a67e3dd02..de55a4eb7 100644 --- a/netbox/resource_netbox_virtualization_vm.go +++ b/netbox/resource_netbox_virtualization_vm.go @@ -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" @@ -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 + }, }, }, } @@ -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, @@ -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 }