Skip to content

Commit

Permalink
Merge pull request #147 from amhn/Fix-vcpus-panic
Browse files Browse the repository at this point in the history
fix: Prevent panic if vcpus is null
  • Loading branch information
smutel authored Sep 30, 2022
2 parents 74c2e4f + 82ad49f commit 2c267c2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions netbox/resource_netbox_virtualization_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ func resourceNetboxVirtualizationVMCreate(ctx context.Context, d *schema.Resourc
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 @@ -338,7 +334,13 @@ func resourceNetboxVirtualizationVMRead(ctx context.Context, d *schema.ResourceD
}
}

if err = d.Set("vcpus", fmt.Sprintf("%v", *resource.Vcpus)); err != nil {
var vcpus string
if resource.Vcpus == nil {
vcpus = ""
} else {
vcpus = fmt.Sprintf("%v", *resource.Vcpus)
}
if err = d.Set("vcpus", vcpus); err != nil {
return diag.FromErr(err)
}

Expand Down Expand Up @@ -419,7 +421,7 @@ func resourceNetboxVirtualizationVMUpdate(ctx context.Context, d *schema.Resourc
params.Tenant = &tenantID
}

if d.HasChange("vcpus") {
if _, ok := d.GetOk("vcpus"); d.HasChange("vcpus") && ok {
vcpus := d.Get("vcpus").(string)

if !strings.Contains(vcpus, ".") {
Expand Down

0 comments on commit 2c267c2

Please sign in to comment.