From 3d19e0f93c7c4427a46ea9ed70e5bd4e93838127 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Thu, 22 Feb 2024 08:07:20 -0500 Subject: [PATCH] guard against nil pointer dereference --- .../device_allocation_system_attributes.go | 4 ++-- ...source_datacenter_device_allocation_test.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/apstra/blueprint/device_allocation_system_attributes.go b/apstra/blueprint/device_allocation_system_attributes.go index 79be5ab0..52e9ac1c 100644 --- a/apstra/blueprint/device_allocation_system_attributes.go +++ b/apstra/blueprint/device_allocation_system_attributes.go @@ -429,8 +429,8 @@ func (o *DeviceAllocationSystemAttributes) setProperties(ctx context.Context, bp func (o *DeviceAllocationSystemAttributes) setTags(ctx context.Context, state *DeviceAllocationSystemAttributes, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { // not a Computed value, so IsNull() will suffice - if o.Tags.IsNull() && len(state.Tags.Elements()) == 0 { - // tags not supplied by user indicates we intend to clear them + if len(o.Tags.Elements()) == 0 && (state == nil || len(state.Tags.Elements()) == 0) { + // user supplied no tags (requiring us to clear them), but state indicates no tags exist return } diff --git a/apstra/resource_datacenter_device_allocation_test.go b/apstra/resource_datacenter_device_allocation_test.go index 420bf740..60555aaa 100644 --- a/apstra/resource_datacenter_device_allocation_test.go +++ b/apstra/resource_datacenter_device_allocation_test.go @@ -492,6 +492,24 @@ func TestResourceDatacenterDeviceAllocation(t *testing.T) { }, }, }, + "bug_584": { + steps: []testStep{ + { + config: deviceAllocation{ + blueprintId: bpClient.Id().String(), + nodeName: "l2_one_access_001_leaf1", + initialInterfaceMapId: "Juniper_vQFX__AOS-7x10-Leaf", + systemAttributes: &systemAttributes{ + deployMode: "drain", + }, + }, + checks: []resource.TestCheckFunc{ + resource.TestCheckResourceAttr(resourceDataCenterDeviceAllocationRefName, "blueprint_id", bpClient.Id().String()), + resource.TestCheckResourceAttr(resourceDataCenterDeviceAllocationRefName, "deploy_mode", utils.StringersToFriendlyString(apstra.NodeDeployModeDrain)), + }, + }, + }, + }, } for tName, tCase := range testCases {