Skip to content

Commit

Permalink
Merge pull request #916 from Juniper/892-deprecate-l3_server-logical-…
Browse files Browse the repository at this point in the history
…device-port-role-for-5x

Bump SDK version
  • Loading branch information
chrismarget-j authored Oct 16, 2024
2 parents 331ec93 + 63f63ae commit 8170777
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 140 deletions.
2 changes: 1 addition & 1 deletion apstra/blueprint/datacenter_generic_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (o *DatacenterGenericSystem) CreateRequest(ctx context.Context, diags *diag
StartIndex: 1,
Schema: apstra.PortIndexingSchemaAbsolute,
},
PortGroups: []apstra.LogicalDevicePortGroup{{Count: 1, Speed: "100M", Roles: 0}},
PortGroups: []apstra.LogicalDevicePortGroup{{Count: 1, Speed: "100M", Roles: apstra.LogicalDevicePortRoles{}}},
}},
},
}
Expand Down
6 changes: 3 additions & 3 deletions apstra/blueprint/vn_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package blueprint

import (
"context"

"github.com/Juniper/apstra-go-sdk/apstra"
apstradefault "github.com/Juniper/terraform-provider-apstra/apstra/defaults"
"github.com/Juniper/terraform-provider-apstra/apstra/design"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework/attr"
dataSourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand All @@ -25,7 +26,6 @@ func (o VnBinding) attrTypes() map[string]attr.Type {
"vlan_id": types.Int64Type,
"access_ids": types.SetType{ElemType: types.StringType},
}

}

func (o VnBinding) DataSourceAttributes() map[string]dataSourceSchema.Attribute {
Expand Down Expand Up @@ -74,7 +74,7 @@ func (o VnBinding) ResourceAttributes() map[string]resourceSchema.Attribute {
Optional: true,
Computed: true,
ElementType: types.StringType,
Default: apstradefault.StaticDefaultAny(types.SetValueMust(types.StringType, []attr.Value{})),
Default: setdefault.StaticValue(types.SetValueMust(types.StringType, []attr.Value{})),
},
}
}
Expand Down
77 changes: 0 additions & 77 deletions apstra/defaults/default_any.go

This file was deleted.

30 changes: 0 additions & 30 deletions apstra/defaults/port_roles.go

This file was deleted.

5 changes: 3 additions & 2 deletions apstra/design/logical_device_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package design
import (
"context"
"fmt"
"strings"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"strings"
)

type LogicalDevicePanel struct {
Expand Down Expand Up @@ -134,7 +135,7 @@ func (o *LogicalDevicePanel) Request(ctx context.Context, diags *diag.Diagnostic
if diags.HasError() {
return nil
}
var reqRoles apstra.LogicalDevicePortRoleFlags
var reqRoles apstra.LogicalDevicePortRoles
err := reqRoles.FromStrings(roleStrings)
if err != nil {
diags.AddError(fmt.Sprintf("error parsing port roles: '%s'", strings.Join(roleStrings, "','")), err.Error())
Expand Down
24 changes: 16 additions & 8 deletions apstra/design/logical_device_panel_port_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package design
import (
"context"
"fmt"
"strings"

"github.com/Juniper/apstra-go-sdk/apstra"
apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator"
apstradefault "github.com/Juniper/terraform-provider-apstra/apstra/defaults"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
Expand All @@ -15,11 +16,11 @@ import (
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"strings"
)

type LogicalDevicePanelPortGroup struct {
Expand Down Expand Up @@ -47,8 +48,15 @@ func (o LogicalDevicePanelPortGroup) DataSourceAttributes() map[string]dataSourc
}

func (o LogicalDevicePanelPortGroup) ResourceAttributes() map[string]resourceSchema.Attribute {
var allRoleFlagsSet apstra.LogicalDevicePortRoleFlags
allRoleFlagsSet.SetAll()
// collect all port roles for use in inline documentation and defaulter
var allPortRoles apstra.LogicalDevicePortRoles
allPortRoles.IncludeAllUses()

// prepare []attr.Value for defaulter
defaultRoles := make([]attr.Value, len(allPortRoles.Strings()))
for i, role := range allPortRoles.Strings() {
defaultRoles[i] = types.StringValue(role)
}

return map[string]resourceSchema.Attribute{
"port_count": resourceSchema.Int64Attribute{
Expand All @@ -68,13 +76,13 @@ func (o LogicalDevicePanelPortGroup) ResourceAttributes() map[string]resourceSch
Computed: true,
Optional: true,
MarkdownDescription: fmt.Sprintf(
"One or more of: '%s', by default all values except 'unused' are selected",
strings.Join(allRoleFlagsSet.Strings(), "', '")),
"One or more of: '%s', by default all values are selected.",
strings.Join(allPortRoles.Strings(), "', '")),
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(stringvalidator.OneOf(allRoleFlagsSet.Strings()...)),
setvalidator.ValueStringsAre(stringvalidator.OneOf(allPortRoles.Strings()...)),
},
Default: apstradefault.PortRolesDefault{},
Default: setdefault.StaticValue(types.SetValueMust(types.StringType, defaultRoles)),
},
}
}
Expand Down
5 changes: 2 additions & 3 deletions apstra/freeform/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,15 @@ func (o *System) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.F
Label: o.Name.ValueString(),
Hostname: o.Hostname.ValueString(),
Tags: tags,
DeviceProfileId: apstra.ObjectId(o.DeviceProfileId.ValueString()),
DeviceProfileId: (*apstra.ObjectId)(o.DeviceProfileId.ValueStringPointer()),
}
}

func (o *System) LoadApiData(ctx context.Context, in *apstra.FreeformSystemData, diags *diag.Diagnostics) {
o.Name = types.StringValue(in.Label)
o.Hostname = types.StringValue(in.Hostname)
o.Type = types.StringValue(utils.StringersToFriendlyString(in.Type))
o.DeviceProfileId = types.StringValue(string(in.DeviceProfileId))
o.DeviceProfileId = utils.StringValueOrNull(ctx, in.DeviceProfileId.String(), diags)
o.DeviceProfileId = types.StringPointerValue((*string)(in.DeviceProfileId))
o.SystemId = types.StringPointerValue((*string)(in.SystemId))
o.Tags = utils.SetValueOrNull(ctx, types.StringType, in.Tags, diags) // safe to ignore diagnostic here
}
26 changes: 15 additions & 11 deletions apstra/resource_interface_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"regexp"
"sort"
"strconv"
"strings"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
"github.com/Juniper/terraform-provider-apstra/apstra/utils"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
Expand All @@ -19,10 +25,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"regexp"
"sort"
"strconv"
"strings"
)

const (
Expand All @@ -31,9 +33,11 @@ const (
ldInterfaceSynax = "<panel>" + ldInterfaceSep + "<port>"
)

var _ resource.ResourceWithConfigure = &resourceInterfaceMap{}
var _ resource.ResourceWithValidateConfig = &resourceInterfaceMap{}
var _ resourceWithSetClient = &resourceInterfaceMap{}
var (
_ resource.ResourceWithConfigure = &resourceInterfaceMap{}
_ resource.ResourceWithValidateConfig = &resourceInterfaceMap{}
_ resourceWithSetClient = &resourceInterfaceMap{}
)

type resourceInterfaceMap struct {
client *apstra.Client
Expand Down Expand Up @@ -519,7 +523,7 @@ func (o *rInterfaceMap) iMapInterfaces(ctx context.Context, ld *apstra.LogicalDe
transformId: transformId,
interfaces: unused,
}
//sliceWithoutInt(transformInterfacesUnused, transformInterface.InterfaceId)
// sliceWithoutInt(transformInterfacesUnused, transformInterface.InterfaceId)
} else {
// New port+transform.
// Add it to the tracking map with this interface ID removed from the list
Expand Down Expand Up @@ -572,7 +576,7 @@ func (o *rInterfaceMap) iMapInterfaces(ctx context.Context, ld *apstra.LogicalDe
}
result = append(result, apstra.InterfaceMapInterface{
Name: intf.Name,
Roles: apstra.LogicalDevicePortRoleUnused,
Roles: apstra.LogicalDevicePortRoles{enum.PortRoleUnused},
Mapping: apstra.InterfaceMapMapping{
DPPortId: portId,
DPTransformId: unused.transformId,
Expand Down Expand Up @@ -756,7 +760,7 @@ func ldPanelAndPortFromString(in string, diags *diag.Diagnostics) (int, int) {

type ldPortInfo struct {
Speed apstra.LogicalDevicePortSpeed
Roles apstra.LogicalDevicePortRoleFlags
Roles apstra.LogicalDevicePortRoles
}

// getLogicalDevicePortInfo extracts a map[string]ldPortInfo keyed by logical
Expand Down Expand Up @@ -836,7 +840,7 @@ func iMapUnallocaedInterfaces(allocatedPorts []apstra.InterfaceMapInterface, dp

result[i] = apstra.InterfaceMapInterface{
Name: transformation.Interfaces[0].Name,
Roles: apstra.LogicalDevicePortRoleUnused,
Roles: apstra.LogicalDevicePortRoles{enum.PortRoleUnused},
Mapping: apstra.InterfaceMapMapping{
DPPortId: dpPort.PortId,
DPTransformId: transformation.TransformationId,
Expand Down
2 changes: 1 addition & 1 deletion apstra/test_utils/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func FfBlueprintB(t testing.TB, ctx context.Context, intSystemCount, extSystemCo
intSystemIds[i], err = c.CreateSystem(ctx, &apstra.FreeformSystemData{
Type: apstra.SystemTypeInternal,
Label: acctest.RandString(6),
DeviceProfileId: dpId,
DeviceProfileId: &dpId,
})
require.NoError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/logical_device.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Required:

Optional:

- `port_roles` (Set of String) One or more of: 'spine', 'superspine', 'leaf', 'access', 'l3_server', 'peer', 'unused', 'generic', by default all values except 'unused' are selected
- `port_roles` (Set of String) One or more of: 'access', 'generic', 'leaf', 'peer', 'spine', 'superspine', 'unused', by default all values are selected.



2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go 1.22.5

require (
github.com/IBM/netaddr v1.5.0
github.com/Juniper/apstra-go-sdk v0.0.0-20241004155941-a48e304bd4b2
github.com/Juniper/apstra-go-sdk v0.0.0-20241010000234-c27c2a93c8cc
github.com/chrismarget-j/go-licenses v0.0.0-20240224210557-f22f3e06d3d4
github.com/chrismarget-j/version-constraints v0.0.0-20240925155624-26771a0a6820
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/IBM/netaddr v1.5.0 h1:IJlFZe1+nFs09TeMB/HOP4+xBnX2iM/xgiDOgZgTJq0=
github.com/IBM/netaddr v1.5.0/go.mod h1:DDBPeYgbFzoXHjSz9Jwk7K8wmWV4+a/Kv0LqRnb8we4=
github.com/Juniper/apstra-go-sdk v0.0.0-20241004155941-a48e304bd4b2 h1:6O56557qPVaB2EZdjVR/OC+ZFF/mpKPTHDD9ATSE6CA=
github.com/Juniper/apstra-go-sdk v0.0.0-20241004155941-a48e304bd4b2/go.mod h1:qXNVTdnVa40aMTOsBTnKoFNYT5ftga2NAkGJhx4o6bY=
github.com/Juniper/apstra-go-sdk v0.0.0-20241010000234-c27c2a93c8cc h1:RjkmXaPqbCWNWc7QoS2O71dh+hNideqLWkY5fLgHGls=
github.com/Juniper/apstra-go-sdk v0.0.0-20241010000234-c27c2a93c8cc/go.mod h1:qXNVTdnVa40aMTOsBTnKoFNYT5ftga2NAkGJhx4o6bY=
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down

0 comments on commit 8170777

Please sign in to comment.