diff --git a/apstra/analytics/telemetry_service_registry_entry.go b/apstra/analytics/telemetry_service_registry_entry.go index a4ad3083..9f801f40 100644 --- a/apstra/analytics/telemetry_service_registry_entry.go +++ b/apstra/analytics/telemetry_service_registry_entry.go @@ -4,6 +4,8 @@ import ( "context" "strings" + "github.com/Juniper/apstra-go-sdk/apstra/enum" + "github.com/Juniper/apstra-go-sdk/apstra" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-jsontypes/jsontypes" @@ -71,11 +73,11 @@ func (o TelemetryServiceRegistryEntry) ResourceAttributes() map[string]resourceS Required: true, }, "storage_schema_path": resourceSchema.StringAttribute{ - MarkdownDescription: "Storage Schema Path. Must be one of:\n - " + strings.Join([]string{utils.StringersToFriendlyString(apstra.StorageSchemaPathIBA_STRING_DATA), utils.StringersToFriendlyString(apstra.StorageSchemaPathIBA_INTEGER_DATA)}, "\n - ") + "\n", + MarkdownDescription: "Storage Schema Path. Must be one of:\n - " + strings.Join([]string{utils.StringersToFriendlyString(enum.StorageSchemaPathIBA_STRING_DATA), utils.StringersToFriendlyString(enum.StorageSchemaPathIBA_INTEGER_DATA)}, "\n - ") + "\n", Required: true, Validators: []validator.String{ stringvalidator.LengthAtLeast(1), - stringvalidator.OneOf(utils.StringersToFriendlyString(apstra.StorageSchemaPathIBA_STRING_DATA), utils.StringersToFriendlyString(apstra.StorageSchemaPathIBA_INTEGER_DATA)), + stringvalidator.OneOf(utils.StringersToFriendlyString(enum.StorageSchemaPathIBA_STRING_DATA), utils.StringersToFriendlyString(enum.StorageSchemaPathIBA_INTEGER_DATA)), }, }, "description": resourceSchema.StringAttribute{ @@ -104,7 +106,7 @@ func (o *TelemetryServiceRegistryEntry) LoadApiData(ctx context.Context, in *aps } func (o *TelemetryServiceRegistryEntry) Request(_ context.Context, diags *diag.Diagnostics) *apstra.TelemetryServiceRegistryEntry { - var storageSchemaPath apstra.StorageSchemaPath + var storageSchemaPath enum.StorageSchemaPath err := utils.ApiStringerFromFriendlyString(&storageSchemaPath, o.StorageSchemaPath.ValueString()) if err != nil { diags.AddError("Failed to Parse Storage Schema Path", err.Error()) diff --git a/apstra/blueprint/blueprint.go b/apstra/blueprint/blueprint.go index c5db0b80..55cc84f7 100644 --- a/apstra/blueprint/blueprint.go +++ b/apstra/blueprint/blueprint.go @@ -7,6 +7,7 @@ import ( "strings" "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" apstraplanmodifier "github.com/Juniper/terraform-provider-apstra/apstra/apstra_plan_modifier" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" @@ -844,9 +845,9 @@ func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) } if utils.HasValue(o.EvpnType5Routes) { - result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumDisabled + result.EvpnGenerateType5HostRoutes = &enum.FeatureSwitchEnumDisabled if o.EvpnType5Routes.ValueBool() { - result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumEnabled + result.EvpnGenerateType5HostRoutes = &enum.FeatureSwitchEnumEnabled } } @@ -863,30 +864,30 @@ func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) } if utils.HasValue(o.JunosEvpnMaxNexthopAndInterfaceNumber) { - result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumDisabled + result.JunosEvpnMaxNexthopAndInterfaceNumber = &enum.FeatureSwitchEnumDisabled if o.JunosEvpnMaxNexthopAndInterfaceNumber.ValueBool() { - result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumEnabled + result.JunosEvpnMaxNexthopAndInterfaceNumber = &enum.FeatureSwitchEnumEnabled } } if utils.HasValue(o.JunosEvpnRoutingInstanceModeMacVrf) { - result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumDisabled + result.JunosEvpnRoutingInstanceVlanAware = &enum.FeatureSwitchEnumDisabled if o.JunosEvpnRoutingInstanceModeMacVrf.ValueBool() { - result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumEnabled + result.JunosEvpnRoutingInstanceVlanAware = &enum.FeatureSwitchEnumEnabled } } if utils.HasValue(o.JunosExOverlayEcmp) { - result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumDisabled + result.JunosExOverlayEcmp = &enum.FeatureSwitchEnumDisabled if o.JunosExOverlayEcmp.ValueBool() { - result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumEnabled + result.JunosExOverlayEcmp = &enum.FeatureSwitchEnumEnabled } } if utils.HasValue(o.JunosGracefulRestart) { - result.JunosGracefulRestart = &apstra.FeatureSwitchEnumDisabled + result.JunosGracefulRestart = &enum.FeatureSwitchEnumDisabled if o.JunosGracefulRestart.ValueBool() { - result.JunosGracefulRestart = &apstra.FeatureSwitchEnumEnabled + result.JunosGracefulRestart = &enum.FeatureSwitchEnumEnabled } } @@ -907,9 +908,9 @@ func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) } if utils.HasValue(o.OptimizeRoutingZoneFootprint) { - result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumDisabled + result.OptimiseSzFootprint = &enum.FeatureSwitchEnumDisabled if o.OptimizeRoutingZoneFootprint.ValueBool() { - result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumEnabled + result.OptimiseSzFootprint = &enum.FeatureSwitchEnumEnabled } } @@ -960,10 +961,10 @@ func boolAttrValueFromBoolPtr(b *bool) types.Bool { return types.BoolValue(*b) } -func boolAttrValueFromFeatureswitchEnumPtr(fs *apstra.FeatureSwitchEnum) types.Bool { +func boolAttrValueFromFeatureswitchEnumPtr(fs *enum.FeatureSwitchEnum) types.Bool { if fs == nil { return types.BoolNull() } - return types.BoolValue(fs.Value == apstra.FeatureSwitchEnumEnabled.Value) + return types.BoolValue(fs.Value == enum.FeatureSwitchEnumEnabled.Value) } diff --git a/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go b/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go index 70e41840..3d9bd1be 100644 --- a/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go +++ b/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" @@ -194,8 +195,8 @@ func (o BgpPeeringGenericSystem) attributes(_ context.Context, diags *diag.Diagn // Label: o.Name.ValueString(), // todo is this necessary? Bfd: o.BfdEnabled.ValueBool(), Holdtime: holdTime, - Ipv4Safi: o.Ipv4AddressingType.ValueString() != utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNone), - Ipv6Safi: o.Ipv6AddressingType.ValueString() != utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNone), + Ipv4Safi: o.Ipv4AddressingType.ValueString() != utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNone), + Ipv6Safi: o.Ipv6AddressingType.ValueString() != utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNone), Keepalive: keepaliveTime, LocalAsn: localAsn, NeighborAsnDynamic: o.NeighborAsnDynamic.ValueBool(), diff --git a/apstra/blueprint/datacenter_external_gateway.go b/apstra/blueprint/datacenter_external_gateway.go index a6618096..87c465fa 100644 --- a/apstra/blueprint/datacenter_external_gateway.go +++ b/apstra/blueprint/datacenter_external_gateway.go @@ -3,7 +3,12 @@ package blueprint import ( "context" "fmt" + "math" + "net" + "strings" + "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-nettypes/iptypes" @@ -20,9 +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" - "math" - "net" - "strings" ) type DatacenterExternalGateway struct { @@ -87,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(apstra.RemoteGatewayRouteTypesEnum.Values(), `", "`), - apstra.RemoteGatewayRouteTypesAll.Value), + strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`), + enum.RemoteGatewayRouteTypesAll.Value), Optional: true, Computed: true, - Default: stringdefault.StaticString(apstra.RemoteGatewayRouteTypesAll.Value), - Validators: []validator.String{stringvalidator.OneOf(apstra.RemoteGatewayRouteTypesEnum.Values()...)}, + Default: stringdefault.StaticString(enum.RemoteGatewayRouteTypesAll.Value), + Validators: []validator.String{stringvalidator.OneOf(enum.RemoteGatewayRouteTypesEnum.Values()...)}, }, "local_gateway_nodes": resourceSchema.SetAttribute{ MarkdownDescription: "Set of IDs of switch nodes which will be configured to peer with the External Gateway", @@ -158,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(apstra.RemoteGatewayRouteTypesEnum.Values(), `", "`), - apstra.RemoteGatewayRouteTypesAll.Value), + strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`), + enum.RemoteGatewayRouteTypesAll.Value), Computed: true, }, "local_gateway_nodes": dataSourceSchema.SetAttribute{ @@ -214,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(apstra.RemoteGatewayRouteTypesEnum.Values(), `", "`), - apstra.RemoteGatewayRouteTypesAll.Value), + strings.Join(enum.RemoteGatewayRouteTypesEnum.Values(), `", "`), + enum.RemoteGatewayRouteTypesAll.Value), Optional: true, }, "local_gateway_nodes": dataSourceSchema.SetAttribute{ @@ -232,7 +234,7 @@ func (o DatacenterExternalGateway) DataSourceAttributesAsFilter() map[string]dat } func (o *DatacenterExternalGateway) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.RemoteGatewayData { - routeTypes := apstra.RemoteGatewayRouteTypesEnum.Parse(o.EvpnRouteTypes.ValueString()) + routeTypes := enum.RemoteGatewayRouteTypesEnum.Parse(o.EvpnRouteTypes.ValueString()) // skipping nil check because input validation should make that impossible var localGwNodes []apstra.ObjectId diff --git a/apstra/blueprint/datacenter_generic_system.go b/apstra/blueprint/datacenter_generic_system.go index cd74abc4..456c1cb6 100644 --- a/apstra/blueprint/datacenter_generic_system.go +++ b/apstra/blueprint/datacenter_generic_system.go @@ -9,10 +9,10 @@ import ( "regexp" "sort" - "github.com/Juniper/terraform-provider-apstra/apstra/constants" - "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/constants" "github.com/Juniper/terraform-provider-apstra/apstra/design" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes" @@ -158,10 +158,10 @@ func (o DatacenterGenericSystem) ResourceAttributes() map[string]resourceSchema. }, "deploy_mode": resourceSchema.StringAttribute{ MarkdownDescription: fmt.Sprintf("Set the Apstra Deploy Mode for this Generic System. Default: `%s`", - apstra.DeployModeDeploy), + enum.DeployModeDeploy), Optional: true, Computed: true, - Default: stringdefault.StaticString(apstra.DeployModeDeploy.String()), + Default: stringdefault.StaticString(enum.DeployModeDeploy.String()), Validators: []validator.String{stringvalidator.OneOf(utils.AllNodeDeployModes()...)}, }, "clear_cts_on_destroy": resourceSchema.BoolAttribute{ diff --git a/apstra/blueprint/datacenter_routing_zone.go b/apstra/blueprint/datacenter_routing_zone.go index aac772c7..25d907b8 100644 --- a/apstra/blueprint/datacenter_routing_zone.go +++ b/apstra/blueprint/datacenter_routing_zone.go @@ -7,6 +7,7 @@ import ( "regexp" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/design" @@ -24,7 +25,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" ) -var junosEvpnIrbModeDefault = apstra.JunosEvpnIrbModeAsymmetric.Value +var junosEvpnIrbModeDefault = enum.JunosEvpnIrbModeAsymmetric.Value type DatacenterRoutingZone struct { Id types.String `tfsdk:"id"` @@ -285,7 +286,7 @@ func (o DatacenterRoutingZone) ResourceAttributes() map[string]resourceSchema.At Optional: true, Computed: true, PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}, - Validators: []validator.String{stringvalidator.OneOf(apstra.JunosEvpnIrbModes.Values()...)}, + Validators: []validator.String{stringvalidator.OneOf(enum.JunosEvpnIrbModes.Values()...)}, // Default: DO NOT USE stringdefault.StaticString(apstra.JunosEvpnIrbModeAsymmetric.Value) here // because that will set the attribute for Apstra < 4.2.0 (which do not support it) leading to // confusion. @@ -332,7 +333,7 @@ func (o *DatacenterRoutingZone) Request(ctx context.Context, client *apstra.Clie RoutingPolicyId: apstra.ObjectId(o.RoutingPolicyId.ValueString()), VlanId: vlan, VniId: vni, - JunosEvpnIrbMode: apstra.JunosEvpnIrbModes.Parse(o.JunosEvpnIrbMode.ValueString()), + JunosEvpnIrbMode: enum.JunosEvpnIrbModes.Parse(o.JunosEvpnIrbMode.ValueString()), RtPolicy: &apstra.RtPolicy{ ImportRTs: importRTs, ExportRTs: exportRTs, diff --git a/apstra/blueprint/datacenter_security_policy_rule.go b/apstra/blueprint/datacenter_security_policy_rule.go index ee6c56d7..c9662ed9 100644 --- a/apstra/blueprint/datacenter_security_policy_rule.go +++ b/apstra/blueprint/datacenter_security_policy_rule.go @@ -3,7 +3,10 @@ package blueprint import ( "context" "fmt" + "strings" + "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" @@ -16,7 +19,6 @@ import ( resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" - "strings" ) type DatacenterSecurityPolicyRule struct { @@ -62,14 +64,14 @@ func (o DatacenterSecurityPolicyRule) DataSourceAttributes() map[string]dataSour Computed: true, }, "action": dataSourceSchema.StringAttribute{ - MarkdownDescription: fmt.Sprintf("Security Policy Rule Action; one of: %s", apstra.PolicyRuleActions), + MarkdownDescription: fmt.Sprintf("Security Policy Rule Action; one of: %s", enum.PolicyRuleActions), Computed: true, }, "source_ports": dataSourceSchema.SetNestedAttribute{ MarkdownDescription: fmt.Sprintf("Set of TCP/UDP source ports matched by this rule. A `null` "+ "set matches any port. Applies only when `protocol` is `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolTcp), - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolUdp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolTcp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolUdp), ), Computed: true, NestedObject: dataSourceSchema.NestedAttributeObject{ @@ -79,8 +81,8 @@ func (o DatacenterSecurityPolicyRule) DataSourceAttributes() map[string]dataSour "destination_ports": dataSourceSchema.SetNestedAttribute{ MarkdownDescription: fmt.Sprintf("Set of TCP/UDP destination ports matched by this rule. A `null` "+ "set matches any port. Applies only when `protocol` is `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolTcp), - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolUdp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolTcp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolUdp), ), Computed: true, NestedObject: dataSourceSchema.NestedAttributeObject{ @@ -169,15 +171,15 @@ func (o DatacenterSecurityPolicyRule) ResourceAttributes() map[string]resourceSc Validators: []validator.String{stringvalidator.OneOf(friendlyPolicyRuleProtocols()...)}, }, "action": resourceSchema.StringAttribute{ - MarkdownDescription: fmt.Sprintf("Action - One of: %s", apstra.PolicyRuleActions), + MarkdownDescription: fmt.Sprintf("Action - One of: %s", enum.PolicyRuleActions), Required: true, - Validators: []validator.String{stringvalidator.OneOf(apstra.PolicyRuleActions.Values()...)}, + Validators: []validator.String{stringvalidator.OneOf(enum.PolicyRuleActions.Values()...)}, }, "source_ports": resourceSchema.SetNestedAttribute{ MarkdownDescription: fmt.Sprintf("Set of TCP/UDP source ports matched by this rule. A `null` "+ "set matches any port. Valid only when `protocol` is `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolTcp), - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolUdp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolTcp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolUdp), ), Optional: true, Validators: []validator.Set{ @@ -191,8 +193,8 @@ func (o DatacenterSecurityPolicyRule) ResourceAttributes() map[string]resourceSc "destination_ports": resourceSchema.SetNestedAttribute{ MarkdownDescription: fmt.Sprintf("Set of TCP/UDP destination ports matched by this rule. A `null` "+ "set matches any port. Valid only when `protocol` is `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolTcp), - utils.StringersToFriendlyString(apstra.PolicyRuleProtocolUdp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolTcp), + utils.StringersToFriendlyString(enum.PolicyRuleProtocolUdp), ), Optional: true, Validators: []validator.Set{ @@ -211,10 +213,10 @@ func (o DatacenterSecurityPolicyRule) ResourceAttributes() map[string]resourceSc Validators: []validator.Bool{ apstravalidator.WhenValueAtMustBeBool( path.MatchRelative().AtParent().AtName("protocol"), - types.StringValue(apstra.PolicyRuleProtocolTcp.Value), + types.StringValue(enum.PolicyRuleProtocolTcp.Value), apstravalidator.ValueAtMustBeBool( path.MatchRelative().AtParent().AtName("protocol"), - types.StringValue(apstra.PolicyRuleProtocolTcp.Value), + types.StringValue(enum.PolicyRuleProtocolTcp.Value), true, ), ), @@ -225,11 +227,11 @@ func (o DatacenterSecurityPolicyRule) ResourceAttributes() map[string]resourceSc func (o *DatacenterSecurityPolicyRule) loadApiData(ctx context.Context, in *apstra.PolicyRuleData, diags *diag.Diagnostics) { var established types.Bool - if in.Protocol == apstra.PolicyRuleProtocolTcp { + if in.Protocol == enum.PolicyRuleProtocolTcp { if in.TcpStateQualifier == nil { established = types.BoolValue(false) } else { - established = types.BoolValue(in.TcpStateQualifier.Value == apstra.TcpStateQualifierEstablished.Value) + established = types.BoolValue(in.TcpStateQualifier.Value == enum.TcpStateQualifierEstablished.Value) } } @@ -243,14 +245,14 @@ func (o *DatacenterSecurityPolicyRule) loadApiData(ctx context.Context, in *apst } func (o *DatacenterSecurityPolicyRule) request(ctx context.Context, path path.Path, diags *diag.Diagnostics) *apstra.PolicyRuleData { - var protocol apstra.PolicyRuleProtocol + var protocol enum.PolicyRuleProtocol err := utils.ApiStringerFromFriendlyString(&protocol, o.Protocol.ValueString()) if err != nil { diags.AddAttributeError(path, fmt.Sprintf("failed to parse policy rule protocol %s", o.Protocol), err.Error()) return nil } - action := apstra.PolicyRuleActions.Parse(o.Action.ValueString()) + action := enum.PolicyRuleActions.Parse(o.Action.ValueString()) if action == nil { diags.AddAttributeError( path.AtName("action"), @@ -265,9 +267,9 @@ func (o *DatacenterSecurityPolicyRule) request(ctx context.Context, path path.Pa return nil } - var tcpStateQualifier *apstra.TcpStateQualifier + var tcpStateQualifier *enum.TcpStateQualifier if o.Established.ValueBool() { - tcpStateQualifier = &apstra.TcpStateQualifierEstablished + tcpStateQualifier = &enum.TcpStateQualifierEstablished } return &apstra.PolicyRuleData{ diff --git a/apstra/blueprint/device_allocation_system_attributes.go b/apstra/blueprint/device_allocation_system_attributes.go index 937934a3..74990164 100644 --- a/apstra/blueprint/device_allocation_system_attributes.go +++ b/apstra/blueprint/device_allocation_system_attributes.go @@ -10,6 +10,7 @@ import ( "strconv" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes" @@ -128,7 +129,6 @@ func (o *DeviceAllocationSystemAttributes) ValidateConfig(_ context.Context, exp "Object may be omitted, but must not be empty") return } - } func (o *DeviceAllocationSystemAttributes) Get(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId types.String, diags *diag.Diagnostics) { @@ -281,7 +281,7 @@ func (o *DeviceAllocationSystemAttributes) getProperties(ctx context.Context, bp return } - var deployMode apstra.DeployMode + var deployMode enum.DeployMode err = deployMode.FromString(node.DeployMode) if err != nil { diags.AddError(fmt.Sprintf("failed to parse node %q deploy mode %q", nodeId, node.DeployMode), err.Error()) @@ -429,7 +429,7 @@ func (o *DeviceAllocationSystemAttributes) setProperties(ctx context.Context, bp } if utils.HasValue(o.DeployMode) { - var deployMode apstra.DeployMode + var deployMode enum.DeployMode err := utils.ApiStringerFromFriendlyString(&deployMode, o.DeployMode.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error in rosetta function with deploy_mode = %s", o.DeployMode), err.Error()) @@ -437,7 +437,7 @@ func (o *DeviceAllocationSystemAttributes) setProperties(ctx context.Context, bp } var deployModePayload *string - if deployMode != apstra.DeployModeNone { + if deployMode != enum.DeployModeNone { deployModePayload = utils.ToPtr(deployMode.String()) } diff --git a/apstra/blueprint/ip_link_addressing.go b/apstra/blueprint/ip_link_addressing.go index a57a76f9..6e196ee0 100644 --- a/apstra/blueprint/ip_link_addressing.go +++ b/apstra/blueprint/ip_link_addressing.go @@ -7,17 +7,16 @@ import ( "net" "strings" - "github.com/hashicorp/terraform-plugin-framework/resource" - - "github.com/Juniper/terraform-provider-apstra/apstra/constants" - "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" + "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" @@ -72,7 +71,7 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu MarkdownDescription: fmt.Sprintf("Allowed values: [`%s`]", strings.Join(utils.AllInterfaceNumberingIpv4Types(), "`,`")), Optional: true, Computed: true, - Default: stringdefault.StaticString(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNone)), + Default: stringdefault.StaticString(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNone)), Validators: []validator.String{stringvalidator.OneOf(utils.AllInterfaceNumberingIpv4Types()...)}, }, "switch_ipv4_address": resourceSchema.StringAttribute{ @@ -80,8 +79,8 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu Optional: true, CustomType: cidrtypes.IPv4PrefixType{}, Validators: []validator.String{ - apstravalidator.RequiredWhenValueIs(path.MatchRoot("switch_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNumbered))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNone))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("switch_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNumbered))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNone))), stringvalidator.AlsoRequires(path.MatchRoot("switch_ipv4_address_type")), }, }, @@ -89,7 +88,7 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu MarkdownDescription: fmt.Sprintf("Allowed values: [`%s`]", strings.Join(utils.AllInterfaceNumberingIpv6Types(), "`,`")), Optional: true, Computed: true, - Default: stringdefault.StaticString(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNone)), + Default: stringdefault.StaticString(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNone)), Validators: []validator.String{stringvalidator.OneOf(utils.AllInterfaceNumberingIpv6Types()...)}, }, "switch_ipv6_address": resourceSchema.StringAttribute{ @@ -97,9 +96,9 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu Optional: true, CustomType: cidrtypes.IPv6PrefixType{}, Validators: []validator.String{ - apstravalidator.RequiredWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNumbered))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNone))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeLinkLocal))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNumbered))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNone))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("switch_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeLinkLocal))), stringvalidator.AlsoRequires(path.MatchRoot("switch_ipv6_address_type")), }, }, @@ -107,7 +106,7 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu MarkdownDescription: fmt.Sprintf("Allowed values: [`%s`]", strings.Join(utils.AllInterfaceNumberingIpv4Types(), "`,`")), Optional: true, Computed: true, - Default: stringdefault.StaticString(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNone)), + Default: stringdefault.StaticString(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNone)), Validators: []validator.String{stringvalidator.OneOf(utils.AllInterfaceNumberingIpv4Types()...)}, }, "generic_ipv4_address": resourceSchema.StringAttribute{ @@ -115,8 +114,8 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu Optional: true, CustomType: cidrtypes.IPv4PrefixType{}, Validators: []validator.String{ - apstravalidator.RequiredWhenValueIs(path.MatchRoot("generic_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNumbered))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv4TypeNone))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("generic_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNumbered))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv4_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv4TypeNone))), stringvalidator.AlsoRequires(path.MatchRoot("generic_ipv4_address_type")), }, }, @@ -124,7 +123,7 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu MarkdownDescription: fmt.Sprintf("Allowed values: [`%s`]", strings.Join(utils.AllInterfaceNumberingIpv6Types(), "`,`")), Optional: true, Computed: true, - Default: stringdefault.StaticString(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNone)), + Default: stringdefault.StaticString(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNone)), Validators: []validator.String{stringvalidator.OneOf(utils.AllInterfaceNumberingIpv6Types()...)}, }, "generic_ipv6_address": resourceSchema.StringAttribute{ @@ -132,9 +131,9 @@ func (o IpLinkAddressing) ResourceAttributes() map[string]resourceSchema.Attribu Optional: true, CustomType: cidrtypes.IPv6PrefixType{}, Validators: []validator.String{ - apstravalidator.RequiredWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNumbered))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeNone))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(apstra.InterfaceNumberingIpv6TypeLinkLocal))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNumbered))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeNone))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("generic_ipv6_address_type"), types.StringValue(utils.StringersToFriendlyString(enum.InterfaceNumberingIpv6TypeLinkLocal))), stringvalidator.AlsoRequires(path.MatchRoot("generic_ipv6_address_type")), }, }, diff --git a/apstra/blueprint/utils.go b/apstra/blueprint/utils.go index 14873d40..49256467 100644 --- a/apstra/blueprint/utils.go +++ b/apstra/blueprint/utils.go @@ -3,7 +3,9 @@ package blueprint import ( "context" "fmt" + "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/diag" ) @@ -43,7 +45,7 @@ func NodeTags(ctx context.Context, id string, client apstra.TwoStageL3ClosClient } func friendlyPolicyRuleProtocols() []string { - enums := apstra.PolicyRuleProtocols.Members() + enums := enum.PolicyRuleProtocols.Members() friendlyStrings := make([]string, len(enums)) for i, enum := range enums { diff --git a/apstra/compatibility/api_versions.go b/apstra/compatibility/api_versions.go index b46ec23b..230caf6c 100644 --- a/apstra/compatibility/api_versions.go +++ b/apstra/compatibility/api_versions.go @@ -1,12 +1,13 @@ package compatibility import ( - "github.com/Juniper/apstra-go-sdk/apstra" + "sort" + "strings" + + "github.com/Juniper/apstra-go-sdk/apstra/compatibility" apiversions "github.com/Juniper/terraform-provider-apstra/apstra/api_versions" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/go-version" - "sort" - "strings" ) func SupportedApiVersions() []string { @@ -17,7 +18,7 @@ func SupportedApiVersions() []string { apiversions.Apstra422, } - sdkVersions := apstra.SupportedApiVersions() + sdkVersions := compatibility.SupportedApiVersions() return utils.SliceIntersectionOfAB(providerVersions, sdkVersions) } diff --git a/apstra/data_source_datacenter_security_policy_test.go b/apstra/data_source_datacenter_security_policy_test.go index ff4d1155..87c15647 100644 --- a/apstra/data_source_datacenter_security_policy_test.go +++ b/apstra/data_source_datacenter_security_policy_test.go @@ -3,11 +3,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/resource" "github.com/stretchr/testify/require" - "testing" ) const ( @@ -122,32 +124,32 @@ func TestDatacenterSecurityPolicy(t *testing.T) { Data: &apstra.PolicyRuleData{ Label: "name_0", Description: "description_0", - Protocol: apstra.PolicyRuleProtocolIcmp, - Action: apstra.PolicyRuleActionDeny, + Protocol: enum.PolicyRuleProtocolIcmp, + Action: enum.PolicyRuleActionDeny, }, }, { Data: &apstra.PolicyRuleData{ Label: "name_1", Description: "description_1", - Protocol: apstra.PolicyRuleProtocolIp, - Action: apstra.PolicyRuleActionDenyLog, + Protocol: enum.PolicyRuleProtocolIp, + Action: enum.PolicyRuleActionDenyLog, }, }, { Data: &apstra.PolicyRuleData{ Label: "name_2", Description: "description_2", - Protocol: apstra.PolicyRuleProtocolTcp, - Action: apstra.PolicyRuleActionPermitLog, + Protocol: enum.PolicyRuleProtocolTcp, + Action: enum.PolicyRuleActionPermitLog, }, }, { Data: &apstra.PolicyRuleData{ Label: "name_3", Description: "description_3", - Protocol: apstra.PolicyRuleProtocolTcp, - Action: apstra.PolicyRuleActionPermitLog, + Protocol: enum.PolicyRuleProtocolTcp, + Action: enum.PolicyRuleActionPermitLog, SrcPort: []apstra.PortRange{ {First: 11, Last: 11}, {First: 13, Last: 13}, @@ -208,10 +210,10 @@ func TestDatacenterSecurityPolicy(t *testing.T) { Data: &apstra.PolicyRuleData{ Label: "ssh_established", Description: "ssh established", - Protocol: apstra.PolicyRuleProtocolTcp, - Action: apstra.PolicyRuleActionPermitLog, + Protocol: enum.PolicyRuleProtocolTcp, + Action: enum.PolicyRuleActionPermitLog, SrcPort: []apstra.PortRange{{First: 22, Last: 22}}, - TcpStateQualifier: &apstra.TcpStateQualifierEstablished, + TcpStateQualifier: &enum.TcpStateQualifierEstablished, }, }, }, @@ -244,7 +246,6 @@ func TestDatacenterSecurityPolicy(t *testing.T) { } for tName, tCase := range testCases { - resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ diff --git a/apstra/design/template_pod_based.go b/apstra/design/template_pod_based.go index d8f9f6a0..dee815c5 100644 --- a/apstra/design/template_pod_based.go +++ b/apstra/design/template_pod_based.go @@ -3,6 +3,7 @@ package design import ( "context" "fmt" + "github.com/Juniper/apstra-go-sdk/apstra" apiversions "github.com/Juniper/terraform-provider-apstra/apstra/api_versions" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" @@ -66,6 +67,7 @@ func (o TemplatePodBased) DataSourceAttributes() map[string]dataSourceSchema.Att Attributes: SuperSpine{}.DataSourceAttributes(), }, "fabric_link_addressing": dataSourceSchema.StringAttribute{ + DeprecationMessage: fmt.Sprintf("Apstra %s is not supported by this release. This field must not be used.", apiversions.Apstra410), MarkdownDescription: fmt.Sprintf("Fabric addressing scheme for Spine/Superspine links. Applies only to "+ "Apstra %s.", apiversions.Apstra410), Computed: true, @@ -98,25 +100,12 @@ func (o TemplatePodBased) ResourceAttributes() map[string]resourceSchema.Attribu Attributes: SuperSpine{}.ResourceAttributes(), }, "fabric_link_addressing": resourceSchema.StringAttribute{ + DeprecationMessage: fmt.Sprintf("Apstra %s is not supported by this release. This field must not be used.", apiversions.Apstra410), MarkdownDescription: fmt.Sprintf("Fabric addressing scheme for Spine/SuperSpine links. Required for "+ "Apstra <= %s, not supported by Apstra >= %s.", apiversions.Apstra410, apiversions.Apstra411), - Optional: true, - Computed: true, - Validators: []validator.String{ - stringvalidator.OneOf( - apstra.AddressingSchemeIp4.String(), - apstra.AddressingSchemeIp46.String(), - apstra.AddressingSchemeIp6.String(), - ), - apstravalidator.WhenValueIsString( - types.StringValue(apstra.AddressingSchemeIp6.String()), - apstravalidator.ValueAtMustBeString( - path.MatchRelative().AtParent().AtName("overlay_control_protocol"), - types.StringValue(OverlayControlProtocolStatic), - false, - ), - ), - }, + Optional: true, + Computed: true, + Validators: []validator.String{apstravalidator.MustBeOneOf([]attr.Value{types.StringNull()})}, }, "pod_infos": resourceSchema.MapNestedAttribute{ MarkdownDescription: "Map of Pod Type info (count + details) keyed by Pod Based Template ID.", @@ -149,33 +138,15 @@ func (o *TemplatePodBased) Request(ctx context.Context, diags *diag.Diagnostics) } } - var err error - antiAffinityPolicy := &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, } - var fabricAddressingPolicy *apstra.TemplateFabricAddressingPolicy410Only - if utils.HasValue(o.FabricAddressing) { - var addressingScheme apstra.AddressingScheme - err = addressingScheme.FromString(o.FabricAddressing.ValueString()) - if err != nil { - diags.AddError(errProviderBug, - fmt.Sprintf("error parsing fabric addressing scheme %q - %s", - o.FabricAddressing.ValueString(), err.Error())) - } - fabricAddressingPolicy = &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: addressingScheme, - SpineLeafLinks: addressingScheme, - } - } - return &apstra.CreatePodBasedTemplateRequest{ - DisplayName: o.Name.ValueString(), - Superspine: ss.Request(ctx, diags), - PodInfos: podInfos, - AntiAffinityPolicy: antiAffinityPolicy, - FabricAddressingPolicy: fabricAddressingPolicy, + DisplayName: o.Name.ValueString(), + Superspine: ss.Request(ctx, diags), + PodInfos: podInfos, + AntiAffinityPolicy: antiAffinityPolicy, } } @@ -185,24 +156,10 @@ func (o *TemplatePodBased) LoadApiData(ctx context.Context, in *apstra.TemplateP return } - fabricAddressing := types.StringNull() - if in.FabricAddressingPolicy != nil { - if in.FabricAddressingPolicy.SpineLeafLinks != in.FabricAddressingPolicy.SpineSuperspineLinks { - diags.AddError(errProviderBug, - fmt.Sprintf("Spine/Leaf and Spine/Luperspine addressing do not match: %q vs. %q\n"+ - "We cannot handle this situation.", - in.FabricAddressingPolicy.SpineLeafLinks.String(), - in.FabricAddressingPolicy.SpineSuperspineLinks.String()), - ) - return - } - fabricAddressing = types.StringValue(in.FabricAddressingPolicy.SpineLeafLinks.String()) - } - o.Name = types.StringValue(in.DisplayName) o.SuperSpine = NewDesignTemplateSuperSpineObject(ctx, &in.Superspine, diags) o.PodInfos = NewPodInfoMap(ctx, in, diags) - o.FabricAddressing = fabricAddressing + o.FabricAddressing = types.StringNull() } func (o *TemplatePodBased) CopyWriteOnlyElements(ctx context.Context, src *TemplatePodBased, diags *diag.Diagnostics) { diff --git a/apstra/design/template_rack_based.go b/apstra/design/template_rack_based.go index d224b24b..a8b0043f 100644 --- a/apstra/design/template_rack_based.go +++ b/apstra/design/template_rack_based.go @@ -3,6 +3,7 @@ package design import ( "context" "fmt" + "github.com/Juniper/apstra-go-sdk/apstra" apiversions "github.com/Juniper/terraform-provider-apstra/apstra/api_versions" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" @@ -118,6 +119,7 @@ func (o TemplateRackBased) DataSourceAttributesNested() map[string]dataSourceSch Computed: true, }, "fabric_link_addressing": dataSourceSchema.StringAttribute{ + DeprecationMessage: fmt.Sprintf("Apstra %s is not supported by this release. This field must not be used.", apiversions.Apstra410), MarkdownDescription: fmt.Sprintf("Fabric addressing scheme for Spine/Leaf links. Applies only to "+ "Apstra %s.", apiversions.Apstra410), Computed: true, @@ -165,25 +167,12 @@ func (o TemplateRackBased) ResourceAttributes() map[string]resourceSchema.Attrib }, }, "fabric_link_addressing": resourceSchema.StringAttribute{ + DeprecationMessage: fmt.Sprintf("Apstra %s is not supported by this release. This field must not be used.", apiversions.Apstra410), MarkdownDescription: fmt.Sprintf("Fabric addressing scheme for Spine/Leaf links. Required for "+ "Apstra <= %s, not supported by Apstra >= %s.", apiversions.Apstra410, apiversions.Apstra411), - Optional: true, - Computed: true, - Validators: []validator.String{ - stringvalidator.OneOf( - apstra.AddressingSchemeIp4.String(), - apstra.AddressingSchemeIp46.String(), - apstra.AddressingSchemeIp6.String(), - ), - apstravalidator.WhenValueIsString( - types.StringValue(apstra.AddressingSchemeIp6.String()), - apstravalidator.ValueAtMustBeString( - path.MatchRelative().AtParent().AtName("overlay_control_protocol"), - types.StringValue(OverlayControlProtocolStatic), - false, - ), - ), - }, + Optional: true, + Computed: true, + Validators: []validator.String{apstravalidator.MustBeOneOf([]attr.Value{types.StringNull()})}, }, "rack_infos": resourceSchema.MapNestedAttribute{ MarkdownDescription: "Map of Rack Type info (count + details) keyed by Rack Type ID.", @@ -272,21 +261,6 @@ func (o *TemplateRackBased) Request(ctx context.Context, diags *diag.Diagnostics SpineAsnScheme: spineAsnScheme, } - var fabricAddressingPolicy *apstra.TemplateFabricAddressingPolicy410Only - if utils.HasValue(o.FabricAddressing) { - var addressingScheme apstra.AddressingScheme - err = addressingScheme.FromString(o.FabricAddressing.ValueString()) - if err != nil { - diags.AddError(errProviderBug, - fmt.Sprintf("error parsing fabric addressing scheme %q - %s", - o.FabricAddressing.ValueString(), err.Error())) - } - fabricAddressingPolicy = &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: addressingScheme, - SpineLeafLinks: addressingScheme, - } - } - var overlayControlProtocol apstra.OverlayControlProtocol err = utils.ApiStringerFromFriendlyString(&overlayControlProtocol, o.OverlayControlProtocol.ValueString()) if err != nil { @@ -305,10 +279,9 @@ func (o *TemplateRackBased) Request(ctx context.Context, diags *diag.Diagnostics DhcpServiceIntent: &apstra.DhcpServiceIntent{Active: true}, // todo: is this the right AntiAffinityPolicy? // I'd have sent , but blocked by sdk issue #2 (crash on nil pointer deref) - AntiAffinityPolicy: antiAffinityPolicy, - AsnAllocationPolicy: asnAllocationPolicy, - FabricAddressingPolicy: fabricAddressingPolicy, - VirtualNetworkPolicy: virtualNetworkPolicy, + AntiAffinityPolicy: antiAffinityPolicy, + AsnAllocationPolicy: asnAllocationPolicy, + VirtualNetworkPolicy: virtualNetworkPolicy, } } @@ -318,26 +291,12 @@ func (o *TemplateRackBased) LoadApiData(ctx context.Context, in *apstra.Template return } - fabricAddressing := types.StringNull() - if in.FabricAddressingPolicy != nil { - if in.FabricAddressingPolicy.SpineLeafLinks != in.FabricAddressingPolicy.SpineSuperspineLinks { - diags.AddError(errProviderBug, - fmt.Sprintf("Spine/Leaf and Spine/Luperspine addressing do not match: %q vs. %q\n"+ - "We cannot handle this situation.", - in.FabricAddressingPolicy.SpineLeafLinks.String(), - in.FabricAddressingPolicy.SpineSuperspineLinks.String()), - ) - return - } - fabricAddressing = types.StringValue(in.FabricAddressingPolicy.SpineLeafLinks.String()) - } - o.Name = types.StringValue(in.DisplayName) o.Spine = NewDesignTemplateSpineObject(ctx, &in.Spine, diags) o.AsnAllocation = types.StringValue(utils.StringersToFriendlyString(in.AsnAllocationPolicy.SpineAsnScheme)) o.OverlayControlProtocol = types.StringValue(utils.StringersToFriendlyString(in.VirtualNetworkPolicy.OverlayControlProtocol)) o.RackInfos = NewRackInfoMap(ctx, in, diags) - o.FabricAddressing = fabricAddressing + o.FabricAddressing = types.StringNull() } func (o *TemplateRackBased) CopyWriteOnlyElements(ctx context.Context, src *TemplateRackBased, diags *diag.Diagnostics) { diff --git a/apstra/freeform/allocation_group.go b/apstra/freeform/allocation_group.go index ffb4ed98..53db6460 100644 --- a/apstra/freeform/allocation_group.go +++ b/apstra/freeform/allocation_group.go @@ -7,6 +7,7 @@ import ( "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/setvalidator" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -107,7 +108,7 @@ func (o AllocGroup) ResourceAttributes() map[string]resourceSchema.Attribute { func (o *AllocGroup) Request(ctx context.Context, diags *diag.Diagnostics) *apstra.FreeformAllocGroupData { // unpack - var allocGroupType apstra.ResourcePoolType + var allocGroupType enum.ResourcePoolType err := utils.ApiStringerFromFriendlyString(&allocGroupType, o.Type.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error parsing type %q", o.Type.ValueString()), err.Error()) diff --git a/apstra/freeform/resource.go b/apstra/freeform/resource.go index 7b862f94..7dcbfd7c 100644 --- a/apstra/freeform/resource.go +++ b/apstra/freeform/resource.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-nettypes/cidrtypes" @@ -75,12 +76,12 @@ func (o Resource) DataSourceAttributes() map[string]dataSourceSchema.Attribute { MarkdownDescription: fmt.Sprintf("Value used by integer type resources (`%s`, `%s`, `%s`, `%s`). "+ "Also used by IP prefix resources (`%s` and `%s`) to indicate the required prefix size for automatic "+ "allocations from another object or a resource pool.", - utils.StringersToFriendlyString(apstra.FFResourceTypeAsn), - utils.StringersToFriendlyString(apstra.FFResourceTypeInt), - utils.StringersToFriendlyString(apstra.FFResourceTypeVlan), - utils.StringersToFriendlyString(apstra.FFResourceTypeVni), - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4), - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeAsn), + utils.StringersToFriendlyString(enum.FFResourceTypeInt), + utils.StringersToFriendlyString(enum.FFResourceTypeVlan), + utils.StringersToFriendlyString(enum.FFResourceTypeVni), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv6), ), Computed: true, }, @@ -92,16 +93,16 @@ func (o Resource) DataSourceAttributes() map[string]dataSourceSchema.Attribute { }, "ipv4_value": dataSourceSchema.StringAttribute{ MarkdownDescription: fmt.Sprintf("Value used by resources with type `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4), - utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv4), ), Computed: true, CustomType: cidrtypes.IPv4PrefixType{}, }, "ipv6_value": dataSourceSchema.StringAttribute{ MarkdownDescription: fmt.Sprintf("Value used by resources with type `%s` or `%s`.", - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6), - utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv6), ), Computed: true, CustomType: cidrtypes.IPv6PrefixType{}, @@ -154,48 +155,48 @@ func (o Resource) ResourceAttributes() map[string]resourceSchema.Attribute { MarkdownDescription: fmt.Sprintf("Value used by integer type resources (`%s`, `%s`, `%s`, `%s`). "+ "Also used by IP prefix resources (`%s` and `%s`) to indicate the required prefix size for automatic "+ "allocations from another object or a resource pool.", - utils.StringersToFriendlyString(apstra.FFResourceTypeAsn), - utils.StringersToFriendlyString(apstra.FFResourceTypeInt), - utils.StringersToFriendlyString(apstra.FFResourceTypeVlan), - utils.StringersToFriendlyString(apstra.FFResourceTypeVni), - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4), - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeAsn), + utils.StringersToFriendlyString(enum.FFResourceTypeInt), + utils.StringersToFriendlyString(enum.FFResourceTypeVlan), + utils.StringersToFriendlyString(enum.FFResourceTypeVni), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv6), ), Optional: true, Computed: true, Validators: []validator.Int64{ - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv4))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv6))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv4))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv6))), }, }, "ipv4_value": resourceSchema.StringAttribute{ MarkdownDescription: fmt.Sprintf("Value used by resources with type `%s` or `%s`. Must be CIDR notation.", - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4), - utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv4), ), Optional: true, Computed: true, CustomType: cidrtypes.IPv4PrefixType{}, Validators: []validator.String{ - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeAsn))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeInt))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVlan))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVni))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeAsn))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeInt))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVlan))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVni))), }, }, "ipv6_value": resourceSchema.StringAttribute{ MarkdownDescription: fmt.Sprintf("Value used by resources with type `%s` or `%s`. Must be CIDR notation.", - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6), - utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv6), ), Optional: true, Computed: true, CustomType: cidrtypes.IPv6PrefixType{}, Validators: []validator.String{ - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeAsn))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeInt))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVlan))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVni))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeAsn))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeInt))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVlan))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVni))), }, }, "allocated_from": resourceSchema.StringAttribute{ @@ -220,14 +221,14 @@ func (o Resource) ResourceAttributes() map[string]resourceSchema.Attribute { } func (o *Resource) Request(_ context.Context, diags *diag.Diagnostics) *apstra.FreeformRaResourceData { - var resourceType apstra.FFResourceType + var resourceType enum.FFResourceType err := utils.ApiStringerFromFriendlyString(&resourceType, o.Type.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error parsing type %q", o.Type.ValueString()), err.Error()) } - typeIpv4 := resourceType == apstra.FFResourceTypeIpv4 - typeIpv6 := resourceType == apstra.FFResourceTypeIpv6 + typeIpv4 := resourceType == enum.FFResourceTypeIpv4 + typeIpv6 := resourceType == enum.FFResourceTypeIpv6 var subnetPrefixLen *int if (typeIpv4 || typeIpv6) && utils.HasValue(o.IntValue) { @@ -268,22 +269,22 @@ func (o *Resource) LoadApiData(_ context.Context, in *apstra.FreeformRaResourceD var i int64 if in.Value != nil { switch in.ResourceType { - case apstra.FFResourceTypeAsn, - apstra.FFResourceTypeVni, - apstra.FFResourceTypeVlan, - apstra.FFResourceTypeInt: + case enum.FFResourceTypeAsn, + enum.FFResourceTypeVni, + enum.FFResourceTypeVlan, + enum.FFResourceTypeInt: i, err = strconv.ParseInt(*in.Value, 10, 64) o.IntValue = types.Int64Value(i) - case apstra.FFResourceTypeHostIpv4: + case enum.FFResourceTypeHostIpv4: o.Ipv4Value = cidrtypes.NewIPv4PrefixValue(*in.Value) - case apstra.FFResourceTypeHostIpv6: + case enum.FFResourceTypeHostIpv6: o.Ipv6Value = cidrtypes.NewIPv6PrefixValue(*in.Value) - case apstra.FFResourceTypeIpv4: + case enum.FFResourceTypeIpv4: o.Ipv4Value = cidrtypes.NewIPv4PrefixValue(*in.Value) if in.SubnetPrefixLen != nil { o.IntValue = types.Int64Value(int64(*in.SubnetPrefixLen)) } - case apstra.FFResourceTypeIpv6: + case enum.FFResourceTypeIpv6: o.Ipv6Value = cidrtypes.NewIPv6PrefixValue(*in.Value) if in.SubnetPrefixLen != nil { o.IntValue = types.Int64Value(int64(*in.SubnetPrefixLen)) diff --git a/apstra/freeform/resource_generator.go b/apstra/freeform/resource_generator.go index 265b2adf..c265d4a3 100644 --- a/apstra/freeform/resource_generator.go +++ b/apstra/freeform/resource_generator.go @@ -3,11 +3,13 @@ package freeform import ( "context" "fmt" - apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "regexp" "strings" + "github.com/Juniper/apstra-go-sdk/apstra/enum" + apstravalidator "github.com/Juniper/terraform-provider-apstra/apstra/apstra_validator" + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" + "github.com/Juniper/apstra-go-sdk/apstra" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" @@ -136,27 +138,27 @@ func (o ResourceGenerator) ResourceAttributes() map[string]resourceSchema.Attrib "subnet_prefix_len": resourceSchema.Int64Attribute{ MarkdownDescription: fmt.Sprintf("Length of the subnet for the generated Resources. "+ "Only applicable when `type` is `%s` or `%s`", - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4), - utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv4), + utils.StringersToFriendlyString(enum.FFResourceTypeIpv6), ), Optional: true, Validators: []validator.Int64{ int64validator.Between(1, 127), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeAsn))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv4))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeHostIpv6))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeInt))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVlan))), - apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeVni))), - apstravalidator.RequiredWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeIpv4))), - apstravalidator.RequiredWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(apstra.FFResourceTypeIpv6))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeAsn))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv4))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeHostIpv6))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeInt))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVlan))), + apstravalidator.ForbiddenWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeVni))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeIpv4))), + apstravalidator.RequiredWhenValueIs(path.MatchRoot("type"), types.StringValue(utils.StringersToFriendlyString(enum.FFResourceTypeIpv6))), }, }, } } func (o *ResourceGenerator) Request(_ context.Context, diags *diag.Diagnostics) *apstra.FreeformResourceGeneratorData { - var resourceType apstra.FFResourceType + var resourceType enum.FFResourceType err := utils.ApiStringerFromFriendlyString(&resourceType, o.Type.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error parsing type %q", o.Type.ValueString()), err.Error()) @@ -164,7 +166,7 @@ func (o *ResourceGenerator) Request(_ context.Context, diags *diag.Diagnostics) var scopeNodePoolLabel *string var allocatedFrom *apstra.ObjectId - if resourceType == apstra.FFResourceTypeVlan { + if resourceType == enum.FFResourceTypeVlan { scopeNodePoolLabel = o.AllocatedFrom.ValueStringPointer() } else { allocatedFrom = (*apstra.ObjectId)(o.AllocatedFrom.ValueStringPointer()) @@ -191,7 +193,7 @@ func (o *ResourceGenerator) LoadApiData(_ context.Context, in *apstra.FreeformRe o.Name = types.StringValue(in.Label) o.Scope = types.StringValue(in.Scope) o.Type = types.StringValue(utils.StringersToFriendlyString(in.ResourceType)) - if in.ResourceType == apstra.FFResourceTypeVlan { + if in.ResourceType == enum.FFResourceTypeVlan { o.AllocatedFrom = types.StringPointerValue(in.ScopeNodePoolLabel) } else { o.AllocatedFrom = types.StringPointerValue((*string)(in.AllocatedFrom)) diff --git a/apstra/iba/widget.go b/apstra/iba/widget.go index 1e8dffb6..6f470ee2 100644 --- a/apstra/iba/widget.go +++ b/apstra/iba/widget.go @@ -2,7 +2,9 @@ package iba import ( "context" + "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/stringvalidator" dataSourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" @@ -124,6 +126,6 @@ func (o *Widget) Request(_ context.Context, _ *diag.Diagnostics) *apstra.IbaWidg Description: o.Description.ValueString(), ProbeId: apstra.ObjectId(o.ProbeId.ValueString()), Label: o.Name.ValueString(), - Type: apstra.IbaWidgetTypeStage, + Type: enum.IbaWidgetTypeStage, } } diff --git a/apstra/resource_datacenter_generic_system_test.go b/apstra/resource_datacenter_generic_system_test.go index b7bb046e..b749cb39 100644 --- a/apstra/resource_datacenter_generic_system_test.go +++ b/apstra/resource_datacenter_generic_system_test.go @@ -9,6 +9,7 @@ import ( "testing" "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" testutils "github.com/Juniper/terraform-provider-apstra/apstra/test_utils" "github.com/Juniper/terraform-provider-apstra/apstra/utils" @@ -464,7 +465,7 @@ func TestResourceDatacenterGenericSystem_A(t *testing.T) { // name: "foo", // hostname: "foo.com", // tags: []string{"a"}, - deployMode: apstra.DeployModeReady.String(), + deployMode: enum.DeployModeReady.String(), links: []link{ { lagMode: apstra.RackLinkLagModePassive, @@ -488,7 +489,7 @@ func TestResourceDatacenterGenericSystem_A(t *testing.T) { resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "asn"), resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "loopback_ipv4"), resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "loopback_ipv6"), - resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "deploy_mode", apstra.DeployModeReady.String()), + resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "deploy_mode", enum.DeployModeReady.String()), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.#", "2"), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.0.group_label", "bar"), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.0.lag_mode", apstra.RackLinkLagModePassive.String()), @@ -509,7 +510,7 @@ func TestResourceDatacenterGenericSystem_A(t *testing.T) { // name: "foo", // hostname: "foo.com", // tags: []string{"a"}, - deployMode: apstra.DeployModeDeploy.String(), + deployMode: enum.DeployModeDeploy.String(), links: []link{ { lagMode: apstra.RackLinkLagModePassive, @@ -533,7 +534,7 @@ func TestResourceDatacenterGenericSystem_A(t *testing.T) { resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "asn"), resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "loopback_ipv4"), resource.TestCheckNoResourceAttr("apstra_datacenter_generic_system.test", "loopback_ipv6"), - resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "deploy_mode", apstra.DeployModeDeploy.String()), + resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "deploy_mode", enum.DeployModeDeploy.String()), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.#", "2"), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.0.group_label", "bar"), resource.TestCheckResourceAttr("apstra_datacenter_generic_system.test", "links.0.lag_mode", apstra.RackLinkLagModePassive.String()), diff --git a/apstra/resource_datacenter_ip_link_addressing.go b/apstra/resource_datacenter_ip_link_addressing.go index 9cf95426..d34dfe78 100644 --- a/apstra/resource_datacenter_ip_link_addressing.go +++ b/apstra/resource_datacenter_ip_link_addressing.go @@ -9,12 +9,12 @@ import ( "net" "net/netip" - "github.com/Juniper/terraform-provider-apstra/apstra/constants" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" "github.com/Juniper/terraform-provider-apstra/apstra/blueprint" + "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/utils" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" ) @@ -351,8 +351,8 @@ func (o *resourceDatacenterIpLinkAddressing) Delete(ctx context.Context, req res } // unpack the private state into apstra objects - var switchIpv4AddressType, genericIpv4AddressType apstra.InterfaceNumberingIpv4Type - var switchIpv6AddressType, genericIpv6AddressType apstra.InterfaceNumberingIpv6Type + var switchIpv4AddressType, genericIpv4AddressType enum.InterfaceNumberingIpv4Type + var switchIpv6AddressType, genericIpv6AddressType enum.InterfaceNumberingIpv6Type err = utils.ApiStringerFromFriendlyString(&switchIpv4AddressType, private.SwitchIpv4AddressType) if err != nil { resp.Diagnostics.AddError("failed to parse private data switch_ipv4_address_type", err.Error()) diff --git a/apstra/resource_freeform_resource.go b/apstra/resource_freeform_resource.go index e161cfb5..6d0e93af 100644 --- a/apstra/resource_freeform_resource.go +++ b/apstra/resource_freeform_resource.go @@ -6,6 +6,7 @@ import ( "math" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" "github.com/Juniper/terraform-provider-apstra/apstra/constants" "github.com/Juniper/terraform-provider-apstra/apstra/freeform" "github.com/Juniper/terraform-provider-apstra/apstra/utils" @@ -50,7 +51,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou return } - var resourceType apstra.FFResourceType + var resourceType enum.FFResourceType err := utils.ApiStringerFromFriendlyString(&resourceType, config.Type.ValueString()) if err != nil { resp.Diagnostics.AddAttributeError(path.Root("type"), "failed to parse 'type' attribute", err.Error()) @@ -59,7 +60,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou // Reminder Logic: the unknown state in this function means a value was passed by reference switch resourceType { - case apstra.FFResourceTypeAsn: + case enum.FFResourceTypeAsn: if (config.AllocatedFrom.IsNull() && config.IntValue.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.IntValue.IsNull()) { resp.Diagnostics.AddError( @@ -74,7 +75,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou fmt.Sprintf("When type is %s, value must be between %d and %d, got %s", config.Type, constants.AsnMin, uint32(constants.AsnMax), config.IntValue.String()), ) } - case apstra.FFResourceTypeVni: + case enum.FFResourceTypeVni: if (config.AllocatedFrom.IsNull() && config.IntValue.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.IntValue.IsNull()) { resp.Diagnostics.AddError( @@ -89,7 +90,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou fmt.Sprintf("When type is %s, value must be between %d and %d, got %s", config.Type, constants.VniMin, constants.VniMax, config.IntValue.String()), ) } - case apstra.FFResourceTypeVlan: + case enum.FFResourceTypeVlan: if (config.AllocatedFrom.IsNull() && config.IntValue.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.IntValue.IsNull()) { resp.Diagnostics.AddError( @@ -104,7 +105,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou fmt.Sprintf("When type is %s, value must be between %d and %d, got %s", config.Type, constants.VlanMinUsable, constants.VlanMaxUsable, config.IntValue.String()), ) } - case apstra.FFResourceTypeInt: + case enum.FFResourceTypeInt: if (config.AllocatedFrom.IsNull() && config.IntValue.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.IntValue.IsNull()) { resp.Diagnostics.AddError( @@ -119,7 +120,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou fmt.Sprintf("When type is %s, value must be between %d and %d, got %s", config.Type, 1, uint32(math.MaxUint32), config.IntValue.String()), ) } - case apstra.FFResourceTypeHostIpv4: + case enum.FFResourceTypeHostIpv4: if (config.AllocatedFrom.IsNull() && config.Ipv4Value.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.Ipv4Value.IsNull()) { resp.Diagnostics.AddError( @@ -127,7 +128,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou "Exactly one of `allocated_from` and `ipv4_value` must be set when `type` is set to "+config.Type.String(), ) } - case apstra.FFResourceTypeHostIpv6: + case enum.FFResourceTypeHostIpv6: if (config.AllocatedFrom.IsNull() && config.Ipv6Value.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.Ipv6Value.IsNull()) { resp.Diagnostics.AddError( @@ -135,7 +136,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou "Exactly one of `allocated_from` or `ipv6_value` must be set when `type` is set to "+config.Type.String(), ) } - case apstra.FFResourceTypeIpv4: + case enum.FFResourceTypeIpv4: if (config.AllocatedFrom.IsNull() && config.Ipv4Value.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.Ipv4Value.IsNull()) { resp.Diagnostics.AddError( @@ -162,7 +163,7 @@ func (o *resourceFreeformResource) ValidateConfig(ctx context.Context, req resou fmt.Sprintf("When type is %s, value must be between %d and %d, got %s", config.Type, 1, 32, config.IntValue.String()), ) } - case apstra.FFResourceTypeIpv6: + case enum.FFResourceTypeIpv6: if (config.AllocatedFrom.IsNull() && config.Ipv6Value.IsNull()) || (!config.AllocatedFrom.IsNull() && !config.Ipv6Value.IsNull()) { resp.Diagnostics.AddError( diff --git a/apstra/resource_freeform_resource_generator.go b/apstra/resource_freeform_resource_generator.go index aa00cb30..ce7ed662 100644 --- a/apstra/resource_freeform_resource_generator.go +++ b/apstra/resource_freeform_resource_generator.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" "github.com/Juniper/terraform-provider-apstra/apstra/freeform" "github.com/Juniper/terraform-provider-apstra/apstra/utils" "github.com/hashicorp/terraform-plugin-framework/path" @@ -54,7 +55,7 @@ func (o *resourceFreeformResourceGenerator) ValidateConfig(ctx context.Context, } // Extract the type - var resourceType apstra.FFResourceType + var resourceType enum.FFResourceType err := utils.ApiStringerFromFriendlyString(&resourceType, config.Type.ValueString()) if err != nil { resp.Diagnostics.AddAttributeError(path.Root("type"), "failed to parse 'type' attribute", err.Error()) @@ -62,7 +63,7 @@ func (o *resourceFreeformResourceGenerator) ValidateConfig(ctx context.Context, } // Catch v6-sized prefix specified when requesting a v4 subnet. - if resourceType == apstra.FFResourceTypeIpv4 && config.SubnetPrefixLen.ValueInt64() > 32 { + if resourceType == enum.FFResourceTypeIpv4 && config.SubnetPrefixLen.ValueInt64() > 32 { resp.Diagnostics.AddAttributeError(path.Root("subnet_prefix_len"), " 'subnet_prefix_len' cannot be greater than 32 when 'type' is %s", config.Type.String()) return } diff --git a/apstra/test_utils/blueprint_configlet.go b/apstra/test_utils/blueprint_configlet.go index 18bec9c5..e765371c 100644 --- a/apstra/test_utils/blueprint_configlet.go +++ b/apstra/test_utils/blueprint_configlet.go @@ -2,10 +2,12 @@ package testutils import ( "context" + "testing" + "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/stretchr/testify/require" - "testing" ) func CatalogConfigletA(t testing.TB, ctx context.Context, client *apstra.Client) (apstra.ObjectId, *apstra.ConfigletData) { @@ -73,7 +75,7 @@ func TestWidgetsAB(t testing.TB, ctx context.Context, bpClient *apstra.TwoStageL t.Cleanup(func() { require.NoError(t, bpClient.DeleteIbaProbe(ctx, probeBId)) }) widgetA := apstra.IbaWidgetData{ - Type: apstra.IbaWidgetTypeStage, + Type: enum.IbaWidgetTypeStage, Label: "BGP Session Flapping", ProbeId: probeAId, StageName: "BGP Session", @@ -83,7 +85,7 @@ func TestWidgetsAB(t testing.TB, ctx context.Context, bpClient *apstra.TwoStageL t.Cleanup(func() { require.NoError(t, bpClient.DeleteIbaWidget(ctx, widgetAId)) }) widgetB := apstra.IbaWidgetData{ - Type: apstra.IbaWidgetTypeStage, + Type: enum.IbaWidgetTypeStage, Label: "Drain Traffic Anomaly", ProbeId: probeBId, StageName: "excess_range", diff --git a/apstra/test_utils/telemetry_service_registry_entry.go b/apstra/test_utils/telemetry_service_registry_entry.go index f7abac4f..c2b68b95 100644 --- a/apstra/test_utils/telemetry_service_registry_entry.go +++ b/apstra/test_utils/telemetry_service_registry_entry.go @@ -2,10 +2,11 @@ package testutils import ( "context" - "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "testing" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/stretchr/testify/require" ) @@ -62,7 +63,7 @@ func TelemetryServiceRegistryEntryA(t testing.TB, ctx context.Context) *apstra.T request := apstra.TelemetryServiceRegistryEntry{ ServiceName: acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum), ApplicationSchema: schema, - StorageSchemaPath: apstra.StorageSchemaPathIBA_INTEGER_DATA, + StorageSchemaPath: enum.StorageSchemaPathIBA_INTEGER_DATA, Builtin: false, Description: "Test Telemetry Service A", Version: "", diff --git a/apstra/test_utils/template.go b/apstra/test_utils/template.go index 2258c713..816eaf4b 100644 --- a/apstra/test_utils/template.go +++ b/apstra/test_utils/template.go @@ -2,10 +2,11 @@ package testutils import ( "context" + "testing" + "github.com/Juniper/apstra-go-sdk/apstra" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/stretchr/testify/require" - "testing" ) func TemplateA(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { @@ -29,10 +30,6 @@ func TemplateA(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { RackInfos: map[apstra.ObjectId]apstra.TemplateRackBasedRackInfo{ rackType.Id: {Count: 2}, }, - FabricAddressingPolicy: &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: apstra.AddressingSchemeIp4, - SpineLeafLinks: apstra.AddressingSchemeIp4, - }, AntiAffinityPolicy: &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, MaxLinksPerPort: 1, @@ -69,10 +66,6 @@ func TemplateB(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { "access_switch": {Count: 3}, // single-single "L2_ESI_Access_dual": {Count: 2}, // ESI-ESI }, - FabricAddressingPolicy: &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: apstra.AddressingSchemeIp4, - SpineLeafLinks: apstra.AddressingSchemeIp4, - }, AntiAffinityPolicy: &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, MaxLinksPerPort: 1, @@ -108,10 +101,6 @@ func TemplateC(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { RackInfos: map[apstra.ObjectId]apstra.TemplateRackBasedRackInfo{ "L2_ESI_Access_dual": {Count: 1}, // ESI-ESI }, - FabricAddressingPolicy: &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: apstra.AddressingSchemeIp4, - SpineLeafLinks: apstra.AddressingSchemeIp4, - }, AntiAffinityPolicy: &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, MaxLinksPerPort: 1, @@ -158,10 +147,6 @@ func TemplateD(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { rcid: {Count: 1}, rdid: {Count: 1}, }, - FabricAddressingPolicy: &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: apstra.AddressingSchemeIp4, - SpineLeafLinks: apstra.AddressingSchemeIp4, - }, AntiAffinityPolicy: &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, MaxLinksPerPort: 1, @@ -202,10 +187,6 @@ func TemplateE(t testing.TB, ctx context.Context) *apstra.TemplateRackBased { RackInfos: map[apstra.ObjectId]apstra.TemplateRackBasedRackInfo{ rackTypeF.Id: {Count: 1}, }, - FabricAddressingPolicy: &apstra.TemplateFabricAddressingPolicy410Only{ - SpineSuperspineLinks: apstra.AddressingSchemeIp4, - SpineLeafLinks: apstra.AddressingSchemeIp4, - }, AntiAffinityPolicy: &apstra.AntiAffinityPolicy{ Algorithm: apstra.AlgorithmHeuristic, MaxLinksPerPort: 1, diff --git a/apstra/utils/freeform_resource.go b/apstra/utils/freeform_resource.go index 6031d98d..c58f0edf 100644 --- a/apstra/utils/freeform_resource.go +++ b/apstra/utils/freeform_resource.go @@ -3,11 +3,11 @@ package utils import ( "sort" - "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func AllFFResourceTypes() []string { - members := apstra.FFResourceTypes.Members() + members := enum.FFResourceTypes.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) diff --git a/apstra/utils/interface_numbering.go b/apstra/utils/interface_numbering.go index c2d8a959..e24c57e3 100644 --- a/apstra/utils/interface_numbering.go +++ b/apstra/utils/interface_numbering.go @@ -3,11 +3,11 @@ package utils import ( "sort" - "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func AllInterfaceNumberingIpv4Types() []string { - members := apstra.InterfaceNumberingIpv4Types.Members() + members := enum.InterfaceNumberingIpv4Types.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) @@ -18,7 +18,7 @@ func AllInterfaceNumberingIpv4Types() []string { } func AllInterfaceNumberingIpv6Types() []string { - members := apstra.InterfaceNumberingIpv6Types.Members() + members := enum.InterfaceNumberingIpv6Types.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) diff --git a/apstra/utils/node.go b/apstra/utils/node.go index e2f40031..657385cb 100644 --- a/apstra/utils/node.go +++ b/apstra/utils/node.go @@ -4,10 +4,11 @@ import ( "context" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func AllNodeDeployModes() []string { - members := apstra.DeployModes.Members() + members := enum.DeployModes.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) @@ -27,7 +28,7 @@ func GetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, return "", err } - var deployMode apstra.DeployMode + var deployMode enum.DeployMode err = deployMode.FromString(node.DeployMode) if err != nil { return "", err @@ -37,7 +38,7 @@ func GetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, } func SetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, nodeId string, modeString string) error { - var modeIota apstra.DeployMode + var modeIota enum.DeployMode err := ApiStringerFromFriendlyString(&modeIota, modeString) if err != nil { return err @@ -50,7 +51,7 @@ func SetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, Id: nodeId, } - if modeIota != apstra.DeployModeNone { + if modeIota != enum.DeployModeNone { s := modeIota.String() patch.DeployMode = &s } diff --git a/apstra/utils/resource_pool.go b/apstra/utils/resource_pool.go index 8fe9019d..974b24ba 100644 --- a/apstra/utils/resource_pool.go +++ b/apstra/utils/resource_pool.go @@ -3,11 +3,11 @@ package utils import ( "sort" - "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func AllResourcePoolTypes() []string { - members := apstra.ResourcePoolTypes.Members() + members := enum.ResourcePoolTypes.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) diff --git a/apstra/utils/rosetta.go b/apstra/utils/rosetta.go index 955cdbf3..c7384464 100644 --- a/apstra/utils/rosetta.go +++ b/apstra/utils/rosetta.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) const ( @@ -76,25 +77,25 @@ func StringersToFriendlyString(in ...fmt.Stringer) string { return ctPrimitiveIPv4AddressingTypeToFriendlyString(in0) case apstra.CtPrimitiveIPv6AddressingType: return ctPrimitiveIPv6AddressingTypeToFriendlyString(in0) - case apstra.DeployMode: + case enum.DeployMode: return deployModeToFriendlyString(in0) - case apstra.FFResourceType: + case enum.FFResourceType: return ffResourceTypeToFriendlyString(in0) - case apstra.InterfaceNumberingIpv4Type: + case enum.InterfaceNumberingIpv4Type: return interfaceNumberingIpv4TypeToFriendlyString(in0) - case apstra.InterfaceNumberingIpv6Type: + case enum.InterfaceNumberingIpv6Type: return interfaceNumberingIpv6TypeToFriendlyString(in0) case apstra.OverlayControlProtocol: return overlayControlProtocolToFriendlyString(in0) - case apstra.PolicyRuleProtocol: + case enum.PolicyRuleProtocol: return policyRuleProtocolToFriendlyString(in0) case apstra.RefDesign: return refDesignToFriendlyString(in0) case apstra.ResourceGroupName: return resourceGroupNameToFriendlyString(in0) - case apstra.ResourcePoolType: + case enum.ResourcePoolType: return resourcePoolTypeToFriendlyString(in0) - case apstra.StorageSchemaPath: + case enum.StorageSchemaPath: return storageSchemaPathToFriendlyString(in0) } @@ -122,25 +123,25 @@ func ApiStringerFromFriendlyString(target StringerWithFromString, in ...string) return ctPrimitiveIPv4AddressingTypeFromFriendlyString(target, in...) case *apstra.CtPrimitiveIPv6AddressingType: return ctPrimitiveIPv6AddressingTypeFromFriendlyString(target, in...) - case *apstra.DeployMode: + case *enum.DeployMode: return nodeDeployModeFromFriendlyString(target, in...) - case *apstra.FFResourceType: + case *enum.FFResourceType: return freeformResourceTypeFromFriendlyString(target, in...) - case *apstra.InterfaceNumberingIpv4Type: + case *enum.InterfaceNumberingIpv4Type: return interfaceNumberingIpv4TypeFromFriendlyString(target, in...) - case *apstra.InterfaceNumberingIpv6Type: + case *enum.InterfaceNumberingIpv6Type: return interfaceNumberingIpv6TypeFromFriendlyString(target, in...) case *apstra.OverlayControlProtocol: return overlayControlProtocolFromFriendlyString(target, in...) - case *apstra.PolicyRuleProtocol: + case *enum.PolicyRuleProtocol: return policyRuleProtocolFromFriendlyString(target, in[0]) case *apstra.RefDesign: return refDesignFromFriendlyString(target, in...) case *apstra.ResourceGroupName: return resourceGroupNameFromFriendlyString(target, in...) - case *apstra.ResourcePoolType: + case *enum.ResourcePoolType: return resourcePoolTypeFromFriendlyString(target, in...) - case *apstra.StorageSchemaPath: + case *enum.StorageSchemaPath: return target.FromString("aos.sdk.telemetry.schemas." + in[0]) } @@ -203,38 +204,38 @@ func ctPrimitiveIPv6AddressingTypeToFriendlyString(in apstra.CtPrimitiveIPv6Addr return in.String() } -func deployModeToFriendlyString(in apstra.DeployMode) string { +func deployModeToFriendlyString(in enum.DeployMode) string { switch in { - case apstra.DeployModeNone: + case enum.DeployModeNone: return nodeDeployModeNotSet } return in.String() } -func ffResourceTypeToFriendlyString(in apstra.FFResourceType) string { +func ffResourceTypeToFriendlyString(in enum.FFResourceType) string { switch in { - case apstra.FFResourceTypeHostIpv4: + case enum.FFResourceTypeHostIpv4: return freeformResourceTypeHostIpv4 - case apstra.FFResourceTypeIpv4: + case enum.FFResourceTypeIpv4: return freeformResourceTypeIpv4 } return in.String() } -func interfaceNumberingIpv4TypeToFriendlyString(in apstra.InterfaceNumberingIpv4Type) string { +func interfaceNumberingIpv4TypeToFriendlyString(in enum.InterfaceNumberingIpv4Type) string { switch in { - case apstra.InterfaceNumberingIpv4TypeNone: + case enum.InterfaceNumberingIpv4TypeNone: return interfaceNumberingIpv4TypeNone } return in.String() } -func interfaceNumberingIpv6TypeToFriendlyString(in apstra.InterfaceNumberingIpv6Type) string { +func interfaceNumberingIpv6TypeToFriendlyString(in enum.InterfaceNumberingIpv6Type) string { switch in { - case apstra.InterfaceNumberingIpv6TypeNone: + case enum.InterfaceNumberingIpv6TypeNone: return interfaceNumberingIpv6TypeNone } @@ -250,7 +251,7 @@ func overlayControlProtocolToFriendlyString(in apstra.OverlayControlProtocol) st return in.String() } -func policyRuleProtocolToFriendlyString(in apstra.PolicyRuleProtocol) string { +func policyRuleProtocolToFriendlyString(in enum.PolicyRuleProtocol) string { return strings.ToLower(in.String()) } @@ -263,7 +264,7 @@ func refDesignToFriendlyString(in apstra.RefDesign) string { return in.String() } -func storageSchemaPathToFriendlyString(in apstra.StorageSchemaPath) string { +func storageSchemaPathToFriendlyString(in enum.StorageSchemaPath) string { s := strings.Split(in.String(), ".") return s[len(s)-1] } @@ -287,9 +288,9 @@ func resourceGroupNameToFriendlyString(in apstra.ResourceGroupName) string { return in.String() } -func resourcePoolTypeToFriendlyString(in apstra.ResourcePoolType) string { +func resourcePoolTypeToFriendlyString(in enum.ResourcePoolType) string { switch in { - case apstra.ResourcePoolTypeIpv4: + case enum.ResourcePoolTypeIpv4: return resourcePoolTypeIpv4 } @@ -374,14 +375,14 @@ func ctPrimitiveIPv6AddressingTypeFromFriendlyString(target *apstra.CtPrimitiveI return nil } -func nodeDeployModeFromFriendlyString(target *apstra.DeployMode, in ...string) error { +func nodeDeployModeFromFriendlyString(target *enum.DeployMode, in ...string) error { if len(in) == 0 { return target.FromString("") } switch in[0] { case nodeDeployModeNotSet: - *target = apstra.DeployModeNone + *target = enum.DeployModeNone default: return target.FromString(in[0]) } @@ -389,16 +390,16 @@ func nodeDeployModeFromFriendlyString(target *apstra.DeployMode, in ...string) e return nil } -func freeformResourceTypeFromFriendlyString(target *apstra.FFResourceType, in ...string) error { +func freeformResourceTypeFromFriendlyString(target *enum.FFResourceType, in ...string) error { if len(in) == 0 { return target.FromString("") } switch in[0] { case freeformResourceTypeHostIpv4: - *target = apstra.FFResourceTypeHostIpv4 + *target = enum.FFResourceTypeHostIpv4 case freeformResourceTypeIpv4: - *target = apstra.FFResourceTypeIpv4 + *target = enum.FFResourceTypeIpv4 default: return target.FromString(in[0]) } @@ -406,14 +407,14 @@ func freeformResourceTypeFromFriendlyString(target *apstra.FFResourceType, in .. return nil } -func interfaceNumberingIpv4TypeFromFriendlyString(target *apstra.InterfaceNumberingIpv4Type, in ...string) error { +func interfaceNumberingIpv4TypeFromFriendlyString(target *enum.InterfaceNumberingIpv4Type, in ...string) error { if len(in) == 0 { return target.FromString("") } switch in[0] { case interfaceNumberingIpv4TypeNone: - *target = apstra.InterfaceNumberingIpv4TypeNone + *target = enum.InterfaceNumberingIpv4TypeNone default: return target.FromString(in[0]) } @@ -421,14 +422,14 @@ func interfaceNumberingIpv4TypeFromFriendlyString(target *apstra.InterfaceNumber return nil } -func interfaceNumberingIpv6TypeFromFriendlyString(target *apstra.InterfaceNumberingIpv6Type, in ...string) error { +func interfaceNumberingIpv6TypeFromFriendlyString(target *enum.InterfaceNumberingIpv6Type, in ...string) error { if len(in) == 0 { return target.FromString("") } switch in[0] { case interfaceNumberingIpv6TypeNone: - *target = apstra.InterfaceNumberingIpv6TypeNone + *target = enum.InterfaceNumberingIpv6TypeNone default: return target.FromString(in[0]) } @@ -451,8 +452,8 @@ func overlayControlProtocolFromFriendlyString(target *apstra.OverlayControlProto return nil } -func policyRuleProtocolFromFriendlyString(target *apstra.PolicyRuleProtocol, s string) error { - t := apstra.PolicyRuleProtocols.Parse(strings.ToUpper(s)) +func policyRuleProtocolFromFriendlyString(target *enum.PolicyRuleProtocol, s string) error { + t := enum.PolicyRuleProtocols.Parse(strings.ToUpper(s)) if t == nil { return fmt.Errorf("cannot parse PolicyRuleProtocol %q", s) } @@ -500,14 +501,14 @@ func resourceGroupNameFromFriendlyString(target *apstra.ResourceGroupName, in .. return nil } -func resourcePoolTypeFromFriendlyString(target *apstra.ResourcePoolType, in ...string) error { +func resourcePoolTypeFromFriendlyString(target *enum.ResourcePoolType, in ...string) error { if len(in) == 0 { return target.FromString("") } switch in[0] { case resourcePoolTypeIpv4: - *target = apstra.ResourcePoolTypeIpv4 + *target = enum.ResourcePoolTypeIpv4 default: return target.FromString(in[0]) } diff --git a/apstra/utils/rosetta_test.go b/apstra/utils/rosetta_test.go index 140c5ff7..de418b3a 100644 --- a/apstra/utils/rosetta_test.go +++ b/apstra/utils/rosetta_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/Juniper/apstra-go-sdk/apstra" + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func TestRosetta(t *testing.T) { @@ -30,10 +31,10 @@ func TestRosetta(t *testing.T) { {string: "static", stringers: []fmt.Stringer{apstra.OverlayControlProtocolNone}}, {string: "evpn", stringers: []fmt.Stringer{apstra.OverlayControlProtocolEvpn}}, - {string: "icmp", stringers: []fmt.Stringer{apstra.PolicyRuleProtocolIcmp}}, - {string: "ip", stringers: []fmt.Stringer{apstra.PolicyRuleProtocolIp}}, - {string: "tcp", stringers: []fmt.Stringer{apstra.PolicyRuleProtocolTcp}}, - {string: "udp", stringers: []fmt.Stringer{apstra.PolicyRuleProtocolUdp}}, + {string: "icmp", stringers: []fmt.Stringer{enum.PolicyRuleProtocolIcmp}}, + {string: "ip", stringers: []fmt.Stringer{enum.PolicyRuleProtocolIp}}, + {string: "tcp", stringers: []fmt.Stringer{enum.PolicyRuleProtocolTcp}}, + {string: "udp", stringers: []fmt.Stringer{enum.PolicyRuleProtocolUdp}}, {string: "datacenter", stringers: []fmt.Stringer{apstra.RefDesignTwoStageL3Clos}}, {string: "freeform", stringers: []fmt.Stringer{apstra.RefDesignFreeform}}, @@ -46,10 +47,10 @@ func TestRosetta(t *testing.T) { {string: "spine_superspine_link_ips_ipv6", stringers: []fmt.Stringer{apstra.ResourceGroupNameSuperspineSpineIp6}}, {string: "to_generic_link_ips_ipv6", stringers: []fmt.Stringer{apstra.ResourceGroupNameToGenericLinkIpv6}}, - {string: "ipv4", stringers: []fmt.Stringer{apstra.ResourcePoolTypeIpv4}}, + {string: "ipv4", stringers: []fmt.Stringer{enum.ResourcePoolTypeIpv4}}, - {string: "none", stringers: []fmt.Stringer{apstra.InterfaceNumberingIpv4TypeNone}}, - {string: "none", stringers: []fmt.Stringer{apstra.InterfaceNumberingIpv6TypeNone}}, + {string: "none", stringers: []fmt.Stringer{enum.InterfaceNumberingIpv4TypeNone}}, + {string: "none", stringers: []fmt.Stringer{enum.InterfaceNumberingIpv6TypeNone}}, {string: "none", stringers: []fmt.Stringer{apstra.CtPrimitiveIPv4AddressingTypeNone}}, {string: "none", stringers: []fmt.Stringer{apstra.CtPrimitiveIPv6AddressingTypeNone}}, @@ -77,17 +78,17 @@ func TestRosetta(t *testing.T) { case apstra.AsnAllocationScheme: x := apstra.AsnAllocationScheme(-1) target = &x - case apstra.InterfaceNumberingIpv4Type: - x := apstra.InterfaceNumberingIpv4Type{} + case enum.InterfaceNumberingIpv4Type: + x := enum.InterfaceNumberingIpv4Type{} target = &x - case apstra.InterfaceNumberingIpv6Type: - x := apstra.InterfaceNumberingIpv6Type{} + case enum.InterfaceNumberingIpv6Type: + x := enum.InterfaceNumberingIpv6Type{} target = &x case apstra.OverlayControlProtocol: x := apstra.OverlayControlProtocol(-1) target = &x - case apstra.PolicyRuleProtocol: - x := apstra.PolicyRuleProtocol{} + case enum.PolicyRuleProtocol: + x := enum.PolicyRuleProtocol{} target = &x case apstra.RefDesign: x := apstra.RefDesign(-1) @@ -95,8 +96,8 @@ func TestRosetta(t *testing.T) { case apstra.ResourceGroupName: x := apstra.ResourceGroupName(-1) target = &x - case apstra.ResourcePoolType: - x := apstra.ResourcePoolType{} + case enum.ResourcePoolType: + x := enum.ResourcePoolType{} target = &x } diff --git a/apstra/utils/telemetry_service_registry_entry.go b/apstra/utils/telemetry_service_registry_entry.go index aa3a00bd..544bd7f5 100644 --- a/apstra/utils/telemetry_service_registry_entry.go +++ b/apstra/utils/telemetry_service_registry_entry.go @@ -1,12 +1,13 @@ package utils import ( - "github.com/Juniper/apstra-go-sdk/apstra" "sort" + + "github.com/Juniper/apstra-go-sdk/apstra/enum" ) func AllStorageSchemaPaths() []string { - members := apstra.StorageSchemaPaths.Members() + members := enum.StorageSchemaPaths.Members() result := make([]string, len(members)) for i, member := range members { result[i] = StringersToFriendlyString(member) diff --git a/docs/data-sources/template_pod_based.md b/docs/data-sources/template_pod_based.md index 7da75c07..123ab347 100644 --- a/docs/data-sources/template_pod_based.md +++ b/docs/data-sources/template_pod_based.md @@ -35,7 +35,7 @@ resource "apstra_template_pod_based" "example" { ### Read-Only -- `fabric_link_addressing` (String) Fabric addressing scheme for Spine/Superspine links. Applies only to Apstra 4.1.0. +- `fabric_link_addressing` (String, Deprecated) Fabric addressing scheme for Spine/Superspine links. Applies only to Apstra 4.1.0. - `pod_infos` (Attributes Map) Map of Pod Type info (count + details) (see [below for nested schema](#nestedatt--pod_infos)) - `super_spine` (Attributes) Super Spine layer details (see [below for nested schema](#nestedatt--super_spine)) @@ -53,7 +53,7 @@ Read-Only: Read-Only: - `asn_allocation_scheme` (String) "unique" is for 3-stage designs; "single" is for 5-stage designs. -- `fabric_link_addressing` (String) Fabric addressing scheme for Spine/Leaf links. Applies only to Apstra 4.1.0. +- `fabric_link_addressing` (String, Deprecated) Fabric addressing scheme for Spine/Leaf links. Applies only to Apstra 4.1.0. - `id` (String) ID of the pod inside the 5 stage template. - `name` (String) Name of the pod inside the 5 stage template. - `overlay_control_protocol` (String) Defines the inter-rack virtual network overlay protocol in the fabric. diff --git a/docs/resources/template_pod_based.md b/docs/resources/template_pod_based.md index 7ed0a2a4..65a522fe 100644 --- a/docs/resources/template_pod_based.md +++ b/docs/resources/template_pod_based.md @@ -41,7 +41,7 @@ resource "apstra_template_pod_based" "example" { ### Optional -- `fabric_link_addressing` (String) Fabric addressing scheme for Spine/SuperSpine links. Required for Apstra <= 4.1.0, not supported by Apstra >= 4.1.1. +- `fabric_link_addressing` (String, Deprecated) Fabric addressing scheme for Spine/SuperSpine links. Required for Apstra <= 4.1.0, not supported by Apstra >= 4.1.1. ### Read-Only diff --git a/docs/resources/template_rack_based.md b/docs/resources/template_rack_based.md index fd6bd314..59b562c0 100644 --- a/docs/resources/template_rack_based.md +++ b/docs/resources/template_rack_based.md @@ -55,7 +55,7 @@ resource "apstra_template_rack_based" "r" { ### Optional -- `fabric_link_addressing` (String) Fabric addressing scheme for Spine/Leaf links. Required for Apstra <= 4.1.0, not supported by Apstra >= 4.1.1. +- `fabric_link_addressing` (String, Deprecated) Fabric addressing scheme for Spine/Leaf links. Required for Apstra <= 4.1.0, not supported by Apstra >= 4.1.1. ### Read-Only diff --git a/go.mod b/go.mod index 8de1b327..337f0019 100644 --- a/go.mod +++ b/go.mod @@ -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-20240830190524-b13fda0b2a3a + github.com/Juniper/apstra-go-sdk v0.0.0-20240913170103-3840c5e77a4a github.com/chrismarget-j/go-licenses v0.0.0-20240224210557-f22f3e06d3d4 github.com/google/go-cmp v0.6.0 github.com/hashicorp/go-version v1.7.0 diff --git a/go.sum b/go.sum index e1ac1252..5b54b95b 100644 --- a/go.sum +++ b/go.sum @@ -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-20240830190524-b13fda0b2a3a h1:XKSJTw1oVxF8uOsLmSr3yhb//9K3+mqqwJNxebyvXeI= -github.com/Juniper/apstra-go-sdk v0.0.0-20240830190524-b13fda0b2a3a/go.mod h1:cSUzaIIQzZysIVKgJnt2/jO2EKeAB60Xgbx8yBGwJ8Y= +github.com/Juniper/apstra-go-sdk v0.0.0-20240913170103-3840c5e77a4a h1:oyQStXZ9gUnqyZIW+bcGlwIAnuC/lVtVTYQnD9I4RaI= +github.com/Juniper/apstra-go-sdk v0.0.0-20240913170103-3840c5e77a4a/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=