Skip to content

Commit

Permalink
Merge pull request #957 from Juniper/949-bump-sdk-version-to-absorb-i…
Browse files Browse the repository at this point in the history
…ota-enum-conversion

Bump SDK version to absorb iota -> enum conversion
  • Loading branch information
chrismarget-j authored Oct 30, 2024
2 parents ef7ddd1 + 156320c commit 976bcb4
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 118 deletions.
18 changes: 9 additions & 9 deletions apstra/blueprint/datacenter_external_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ func (o DatacenterExternalGateway) ResourceAttributes() map[string]resourceSchem
},
"evpn_route_types": resourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf(`EVPN route types. Valid values are: ["%s"]. Default: %q`,
strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`),
enum.RemoteGatewayRouteTypesAll.Value),
strings.Join(enum.RemoteGatewayRouteTypes.Values(), `", "`),
enum.RemoteGatewayRouteTypeAll.Value),
Optional: true,
Computed: true,
Default: stringdefault.StaticString(enum.RemoteGatewayRouteTypesAll.Value),
Validators: []validator.String{stringvalidator.OneOf(enum.RemoteGatewayRouteTypesEnum.Values()...)},
Default: stringdefault.StaticString(enum.RemoteGatewayRouteTypeAll.Value),
Validators: []validator.String{stringvalidator.OneOf(enum.RemoteGatewayRouteTypes.Values()...)},
},
"local_gateway_nodes": resourceSchema.SetAttribute{
MarkdownDescription: "Set of IDs of switch nodes which will be configured to peer with the External Gateway",
Expand Down Expand Up @@ -160,8 +160,8 @@ func (o DatacenterExternalGateway) DataSourceAttributes() map[string]dataSourceS
},
"evpn_route_types": dataSourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf(`EVPN route types. Valid values are: ["%s"]. Default: %q`,
strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`),
enum.RemoteGatewayRouteTypesAll.Value),
strings.Join(enum.RemoteGatewayRouteTypes.Values(), `", "`),
enum.RemoteGatewayRouteTypeAll.Value),
Computed: true,
},
"local_gateway_nodes": dataSourceSchema.SetAttribute{
Expand Down Expand Up @@ -216,8 +216,8 @@ func (o DatacenterExternalGateway) DataSourceAttributesAsFilter() map[string]dat
},
"evpn_route_types": dataSourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf(`EVPN route types. Valid values are: ["%s"]. Default: %q`,
strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`),
enum.RemoteGatewayRouteTypesAll.Value),
strings.Join(enum.RemoteGatewayRouteTypes.Values(), `", "`),
enum.RemoteGatewayRouteTypeAll.Value),
Optional: true,
},
"local_gateway_nodes": dataSourceSchema.SetAttribute{
Expand All @@ -234,7 +234,7 @@ func (o DatacenterExternalGateway) DataSourceAttributesAsFilter() map[string]dat
}

func (o *DatacenterExternalGateway) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.RemoteGatewayData {
routeTypes := enum.RemoteGatewayRouteTypesEnum.Parse(o.EvpnRouteTypes.ValueString())
routeTypes := enum.RemoteGatewayRouteTypes.Parse(o.EvpnRouteTypes.ValueString())
// skipping nil check because input validation should make that impossible

var localGwNodes []apstra.ObjectId
Expand Down
29 changes: 15 additions & 14 deletions apstra/blueprint/datacenter_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
apiversions "github.com/Juniper/terraform-provider-apstra/apstra/api_versions"
"github.com/Juniper/terraform-provider-apstra/apstra/compatibility"
"github.com/Juniper/terraform-provider-apstra/apstra/constants"
Expand Down Expand Up @@ -83,7 +84,7 @@ func (o DatacenterVirtualNetwork) DataSourceAttributes() map[string]dataSourceSc
Computed: true,
},
"routing_zone_id": dataSourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf("Routing Zone ID (only applies when `type == %s`", apstra.VnTypeVxlan),
MarkdownDescription: fmt.Sprintf("Routing Zone ID (only applies when `type == %s`", enum.VnTypeVxlan),
Computed: true,
},
"vni": dataSourceSchema.Int64Attribute{
Expand All @@ -97,7 +98,7 @@ func (o DatacenterVirtualNetwork) DataSourceAttributes() map[string]dataSourceSc
"reserve_vlan": dataSourceSchema.BoolAttribute{
MarkdownDescription: fmt.Sprintf("For use only with `%s` type Virtual networks when all `bindings` "+
"use the same VLAN ID. This option reserves the VLAN fabric-wide, even on switches to "+
"which the Virtual Network has not yet been deployed.", apstra.VnTypeVxlan),
"which the Virtual Network has not yet been deployed.", enum.VnTypeVxlan),
Computed: true,
},
"bindings": dataSourceSchema.MapNestedAttribute{
Expand Down Expand Up @@ -189,7 +190,7 @@ func (o DatacenterVirtualNetwork) DataSourceFilterAttributes() map[string]dataSo
Optional: true,
},
"routing_zone_id": dataSourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf("Routing Zone ID (required when `type == %s`)", apstra.VnTypeVxlan),
MarkdownDescription: fmt.Sprintf("Routing Zone ID (required when `type == %s`)", enum.VnTypeVxlan),
Optional: true,
},
"vni": dataSourceSchema.Int64Attribute{
Expand All @@ -203,7 +204,7 @@ func (o DatacenterVirtualNetwork) DataSourceFilterAttributes() map[string]dataSo
"reserve_vlan": dataSourceSchema.BoolAttribute{
MarkdownDescription: fmt.Sprintf("For use only with `%s` type Virtual networks when all `bindings` "+
"use the same VLAN ID. This option reserves the VLAN fabric-wide, even on switches to "+
"which the Virtual Network has not yet been deployed.", apstra.VnTypeVxlan),
"which the Virtual Network has not yet been deployed.", enum.VnTypeVxlan),
Optional: true,
},
"bindings": dataSourceSchema.MapNestedAttribute{
Expand Down Expand Up @@ -307,23 +308,23 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
MarkdownDescription: "Virtual Network Type",
Optional: true,
Computed: true,
Default: stringdefault.StaticString(apstra.VnTypeVxlan.String()),
Default: stringdefault.StaticString(enum.VnTypeVxlan.String()),
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
Validators: []validator.String{
// specifically enumerated types - SDK supports additional
// types which do not make sense in this context.
stringvalidator.OneOf(apstra.VnTypeVlan.String(), apstra.VnTypeVxlan.String()),
stringvalidator.OneOf(enum.VnTypeVlan.String(), enum.VnTypeVxlan.String()),
},
},
"routing_zone_id": resourceSchema.StringAttribute{
MarkdownDescription: fmt.Sprintf("Routing Zone ID (required when `type == %s`", apstra.VnTypeVxlan),
MarkdownDescription: fmt.Sprintf("Routing Zone ID (required when `type == %s`", enum.VnTypeVxlan),
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.LengthAtLeast(1),
apstravalidator.RequiredWhenValueIs(
path.MatchRelative().AtParent().AtName("type"),
types.StringValue(apstra.VnTypeVxlan.String()),
types.StringValue(enum.VnTypeVxlan.String()),
),
apstravalidator.RequiredWhenValueNull(
path.MatchRelative().AtParent().AtName("type"),
Expand All @@ -342,7 +343,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
int64validator.Between(constants.VniMin, constants.VniMax),
apstravalidator.ForbiddenWhenValueIs(
path.MatchRelative().AtParent().AtName("type"),
types.StringValue(apstra.VnTypeVlan.String()),
types.StringValue(enum.VnTypeVlan.String()),
),
},
},
Expand All @@ -354,14 +355,14 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
MarkdownDescription: fmt.Sprintf("For use only with `%s` type Virtual networks "+
"when all `bindings` use the same VLAN ID. This option reserves the VLAN fabric-wide, "+
"even on switches to which the Virtual Network has not yet been deployed. The only "+
"accepted values is `true`.", apstra.VnTypeVxlan.String()),
"accepted values is `true`.", enum.VnTypeVxlan.String()),
Optional: true,
Computed: true,
Validators: []validator.Bool{
apstravalidator.WhenValueIsBool(types.BoolValue(true),
apstravalidator.ValueAtMustBeBool(
path.MatchRelative().AtParent().AtName("type"),
types.StringValue(apstra.VnTypeVxlan.String()),
types.StringValue(enum.VnTypeVxlan.String()),
false,
),
),
Expand All @@ -381,7 +382,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
mapvalidator.SizeAtLeast(1),
apstravalidator.WhenValueAtMustBeMap(
path.MatchRelative().AtParent().AtName("type"),
types.StringValue(apstra.VnTypeVlan.String()),
types.StringValue(enum.VnTypeVlan.String()),
mapvalidator.SizeAtMost(1),
),
},
Expand Down Expand Up @@ -540,7 +541,7 @@ func (o DatacenterVirtualNetwork) ResourceAttributes() map[string]resourceSchema
}

func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.VirtualNetworkData {
var vnType apstra.VnType
var vnType enum.VnType
err := vnType.FromString(o.Type.ValueString())
if err != nil {
diags.Append(
Expand Down Expand Up @@ -570,7 +571,7 @@ func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diag
vnId = &v
}

if o.Type.ValueString() == apstra.VnTypeVlan.String() {
if o.Type.ValueString() == enum.VnTypeVlan.String() {
// Maximum of one binding is required when type==vlan.
// Apstra requires vlan == vni when creating a "vlan" type VN.
// VNI attribute is forbidden when type == VLAN
Expand Down
4 changes: 2 additions & 2 deletions apstra/data_source_datacenter_external_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestDatacenterExternalGateway(t *testing.T) {

rgConfigs := []apstra.RemoteGatewayData{
{
RouteTypes: enum.RemoteGatewayRouteTypesAll,
RouteTypes: enum.RemoteGatewayRouteTypeAll,
LocalGwNodes: leafIds,
GwAsn: rand.Uint32(),
GwIp: randIpvAddressMust(t, "10.0.0.0/8"),
Expand All @@ -60,7 +60,7 @@ func TestDatacenterExternalGateway(t *testing.T) {
Password: &password,
},
{
RouteTypes: enum.RemoteGatewayRouteTypesFiveOnly,
RouteTypes: enum.RemoteGatewayRouteTypeFiveOnly,
LocalGwNodes: leafIds,
GwAsn: rand.Uint32(),
GwIp: randIpvAddressMust(t, "10.0.0.0/8"),
Expand Down
8 changes: 5 additions & 3 deletions apstra/data_source_datacenter_virtual_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ package tfapstra_test
import (
"context"
"fmt"
"testing"

"github.com/Juniper/apstra-go-sdk/apstra"
"github.com/Juniper/apstra-go-sdk/apstra/enum"
testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"testing"
)

const (
Expand Down Expand Up @@ -60,7 +62,7 @@ func TestDatacenterVirtualNetwork(t *testing.T) {
Ipv4Subnet: randIpNetMust(t, "10.0.0.0/16"),
Label: acctest.RandString(5),
SecurityZoneId: zoneId,
VnType: apstra.VnTypeVxlan,
VnType: enum.VnTypeVxlan,
VnBindings: vnBindings,
},
},
Expand All @@ -70,7 +72,7 @@ func TestDatacenterVirtualNetwork(t *testing.T) {
Ipv4Subnet: randIpNetMust(t, "10.1.0.0/16"),
Label: acctest.RandString(5),
SecurityZoneId: zoneId,
VnType: apstra.VnTypeVlan,
VnType: enum.VnTypeVlan,
VnBindings: []apstra.VnBinding{{SystemId: apstra.ObjectId(leafIdStrings[0])}},
},
},
Expand Down
8 changes: 4 additions & 4 deletions apstra/freeform/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (o Link) DataSourceAttributes() map[string]dataSourceSchema.Attribute {
MarkdownDescription: "Endpoints of the Link, a Map keyed by System ID.",
Computed: true,
NestedObject: dataSourceSchema.NestedAttributeObject{
Attributes: Endpoint{}.DatasourceAttributes(),
Attributes: LinkEndpoint{}.DatasourceAttributes(),
},
},
"tags": dataSourceSchema.SetAttribute{
Expand Down Expand Up @@ -115,7 +115,7 @@ func (o Link) ResourceAttributes() map[string]resourceSchema.Attribute {
},
"endpoints": resourceSchema.MapNestedAttribute{
NestedObject: resourceSchema.NestedAttributeObject{
Attributes: Endpoint{}.ResourceAttributes(),
Attributes: LinkEndpoint{}.ResourceAttributes(),
},
PlanModifiers: []planmodifier.Map{mapplanmodifier.RequiresReplace()},
MarkdownDescription: "Endpoints of the Link, a Map keyed by System ID.",
Expand All @@ -141,13 +141,13 @@ func (o *Link) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.Fre
return nil
}

var endpoints map[string]Endpoint
var endpoints map[string]LinkEndpoint
diags.Append(o.Endpoints.ElementsAs(ctx, &endpoints, false)...)
if diags.HasError() {
return nil
}

var epArray [2]apstra.FreeformEndpoint
var epArray [2]apstra.FreeformEthernetEndpoint
var i int
for systemId, endpoint := range endpoints {
epArray[i] = *endpoint.request(ctx, systemId, diags)
Expand Down
24 changes: 12 additions & 12 deletions apstra/freeform/endpoint.go → apstra/freeform/link_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
)

type Endpoint struct {
type LinkEndpoint struct {
InterfaceName types.String `tfsdk:"interface_name"`
InterfaceId types.String `tfsdk:"interface_id"`
TransformationId types.Int64 `tfsdk:"transformation_id"`
Expand All @@ -30,7 +30,7 @@ type Endpoint struct {
Tags types.Set `tfsdk:"tags"`
}

func (o Endpoint) attrTypes() map[string]attr.Type {
func (o LinkEndpoint) attrTypes() map[string]attr.Type {
return map[string]attr.Type{
"interface_name": types.StringType,
"interface_id": types.StringType,
Expand All @@ -41,7 +41,7 @@ func (o Endpoint) attrTypes() map[string]attr.Type {
}
}

func (o Endpoint) DatasourceAttributes() map[string]dataSourceSchema.Attribute {
func (o LinkEndpoint) DatasourceAttributes() map[string]dataSourceSchema.Attribute {
return map[string]dataSourceSchema.Attribute{
"interface_name": dataSourceSchema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -73,7 +73,7 @@ func (o Endpoint) DatasourceAttributes() map[string]dataSourceSchema.Attribute {
}
}

func (o Endpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
func (o LinkEndpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
return map[string]resourceSchema.Attribute{
"interface_name": resourceSchema.StringAttribute{
Optional: true,
Expand Down Expand Up @@ -119,7 +119,7 @@ func (o Endpoint) ResourceAttributes() map[string]resourceSchema.Attribute {
}
}

func (o *Endpoint) request(ctx context.Context, systemId string, diags *diag.Diagnostics) *apstra.FreeformEndpoint {
func (o *LinkEndpoint) request(ctx context.Context, systemId string, diags *diag.Diagnostics) *apstra.FreeformEthernetEndpoint {
var ipNet4, ipNet6 *net.IPNet
if utils.HasValue(o.Ipv4Address) {
var ip4 net.IP
Expand All @@ -140,7 +140,7 @@ func (o *Endpoint) request(ctx context.Context, systemId string, diags *diag.Dia
transformationId = utils.ToPtr(int(o.TransformationId.ValueInt64()))
}

return &apstra.FreeformEndpoint{
return &apstra.FreeformEthernetEndpoint{
SystemId: apstra.ObjectId(systemId),
Interface: apstra.FreeformInterface{
Data: &apstra.FreeformInterfaceData{
Expand All @@ -154,7 +154,7 @@ func (o *Endpoint) request(ctx context.Context, systemId string, diags *diag.Dia
}
}

func (o *Endpoint) loadApiData(ctx context.Context, in apstra.FreeformEndpoint, diags *diag.Diagnostics) {
func (o *LinkEndpoint) loadApiData(ctx context.Context, in apstra.FreeformEthernetEndpoint, diags *diag.Diagnostics) {
if in.Interface.Id == nil {
diags.AddError(
fmt.Sprintf("api returned nil interface Id for system %s", in.SystemId),
Expand Down Expand Up @@ -182,16 +182,16 @@ func (o *Endpoint) loadApiData(ctx context.Context, in apstra.FreeformEndpoint,
o.Tags = utils.SetValueOrNull(ctx, types.StringType, in.Interface.Data.Tags, diags)
}

func newFreeformEndpointMap(ctx context.Context, in [2]apstra.FreeformEndpoint, diags *diag.Diagnostics) types.Map {
endpoints := make(map[string]Endpoint, len(in))
func newFreeformEndpointMap(ctx context.Context, in [2]apstra.FreeformEthernetEndpoint, diags *diag.Diagnostics) types.Map {
endpoints := make(map[string]LinkEndpoint, len(in))
for i := range in {
var endpoint Endpoint
var endpoint LinkEndpoint
endpoint.loadApiData(ctx, in[i], diags)
endpoints[in[i].SystemId.String()] = endpoint
}
if diags.HasError() {
return types.MapNull(types.ObjectType{AttrTypes: Endpoint{}.attrTypes()})
return types.MapNull(types.ObjectType{AttrTypes: LinkEndpoint{}.attrTypes()})
}

return utils.MapValueOrNull(ctx, types.ObjectType{AttrTypes: Endpoint{}.attrTypes()}, endpoints, diags)
return utils.MapValueOrNull(ctx, types.ObjectType{AttrTypes: LinkEndpoint{}.attrTypes()}, endpoints, diags)
}
Loading

0 comments on commit 976bcb4

Please sign in to comment.