Skip to content

Commit

Permalink
Merge pull request #610 from Juniper/bug/609-deprecated-attribute-han…
Browse files Browse the repository at this point in the history
…dling

Bug #609 - fix handling of deprecated attribute
  • Loading branch information
chrismarget-j committed Mar 8, 2024
2 parents d6faec8 + 07049a8 commit 55d0454
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apstra/blueprint/device_allocation_system_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ type DeviceAllocationSystemAttributes struct {

func (o DeviceAllocationSystemAttributes) AttrTypes() map[string]attr.Type {
return map[string]attr.Type{
"asn": types.Int64Type,
"name": types.StringType,
"hostname": types.StringType,
"asn": types.Int64Type,
"loopback_ipv4": cidrtypes.IPv4PrefixType{},
"loopback_ipv6": cidrtypes.IPv6PrefixType{},
"tags": types.SetType{ElemType: types.StringType},
Expand Down
5 changes: 4 additions & 1 deletion apstra/resource_datacenter_device_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ func (o *resourceDeviceAllocation) Create(ctx context.Context, req resource.Crea
// Deprecated attribute in use?
if utils.Known(plan.DeployMode) {
// validators ensure that system_attributes object has been omitted. instantiate a fresh one and copy the deploy mode in there
sa, d := types.ObjectValueFrom(ctx, blueprint.DeviceAllocationSystemAttributes{}.AttrTypes(), basetypes.ObjectAsOptions{})
sa, d := types.ObjectValueFrom(ctx, blueprint.DeviceAllocationSystemAttributes{}.AttrTypes(), blueprint.DeviceAllocationSystemAttributes{
DeployMode: plan.DeployMode,
Tags: types.SetNull(types.StringType),
})
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
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 @@ -19,6 +19,7 @@ resource "apstra_datacenter_device_allocation" "test" {
blueprint_id = %q
node_name = %q
initial_interface_map_id = %q
deploy_mode = %s
system_attributes = %s
}
`
Expand Down Expand Up @@ -94,13 +95,15 @@ func TestResourceDatacenterDeviceAllocation(t *testing.T) {
nodeName string
initialInterfaceMapId string
systemAttributes *systemAttributes
deployMode string
}

renderDeviceAllocation := func(in deviceAllocation) string {
return fmt.Sprintf(resourceDataCenterDeviceAllocationHCL,
in.blueprintId,
in.nodeName,
in.initialInterfaceMapId,
stringOrNull(in.deployMode),
renderSystemAttributes(in.systemAttributes),
)
}
Expand Down Expand Up @@ -530,6 +533,21 @@ func TestResourceDatacenterDeviceAllocation(t *testing.T) {
},
},
},
"bug_609_deprecated_option": {
steps: []testStep{
{
config: deviceAllocation{
blueprintId: bpClient.Id().String(),
nodeName: "l2_one_access_003_leaf1",
initialInterfaceMapId: "Juniper_vQFX__AOS-7x10-Leaf",
deployMode: "drain",
},
checks: []resource.TestCheckFunc{
resource.TestCheckResourceAttrSet(resourceDataCenterDeviceAllocationRefName, "node_id"),
},
},
},
},
}

for tName, tCase := range testCases {
Expand Down

0 comments on commit 55d0454

Please sign in to comment.