Skip to content

Commit

Permalink
Merge pull request #585 from Juniper/bug/584-crash
Browse files Browse the repository at this point in the history
Bug #584: nil pointer dereference when creating `device_allocation` with empty tags
  • Loading branch information
chrismarget-j authored Feb 22, 2024
2 parents 90889a2 + 3d19e0f commit e27e80b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apstra/blueprint/device_allocation_system_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 18 additions & 0 deletions apstra/resource_datacenter_device_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e27e80b

Please sign in to comment.