From 68ab227c4cb19ac161ae7db5143ab659065a3ca9 Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Sat, 13 Jul 2024 15:03:55 -0400 Subject: [PATCH] rename `utils.Known()` to `utils.HasValue()` --- .../apstra_validator/different_from_values.go | 2 +- apstra/blueprint/blueprint.go | 50 +++++++++--------- .../blueprint/datacenter_external_gateway.go | 8 +-- .../datacenter_generic_system_link.go | 6 +-- apstra/blueprint/datacenter_routing_zone.go | 52 +++++++++---------- .../blueprint/datacenter_virtual_network.go | 14 ++--- apstra/blueprint/device_allocation.go | 10 ++-- .../device_allocation_system_attributes.go | 30 +++++------ apstra/blueprint/ip_link_addressing.go | 2 +- apstra/blueprint/node_system_attributes.go | 14 ++--- apstra/blueprint/nodes_system.go | 8 +-- apstra/blueprint/vn_binding.go | 2 +- apstra/blueprint/vn_binding_constructor.go | 2 +- ...ource_datacenter_ct_custom_static_route.go | 2 +- apstra/design/template_pod_based.go | 2 +- apstra/design/template_rack_based.go | 2 +- .../resource_datacenter_device_allocation.go | 4 +- apstra/resource_datacenter_routing_zone.go | 4 +- ...{attr_value_known.go => attr_has_value.go} | 2 +- apstra/utils/strings.go | 2 +- 20 files changed, 109 insertions(+), 109 deletions(-) rename apstra/utils/{attr_value_known.go => attr_has_value.go} (77%) diff --git a/apstra/apstra_validator/different_from_values.go b/apstra/apstra_validator/different_from_values.go index 96672be1..c752820a 100644 --- a/apstra/apstra_validator/different_from_values.go +++ b/apstra/apstra_validator/different_from_values.go @@ -51,7 +51,7 @@ func (o DifferentFromValuesValidator) MarkdownDescription(_ context.Context) str func (o DifferentFromValuesValidator) Validate(ctx context.Context, req DifferentFromValuesValidatorRequest, resp *DifferentFromValuesValidatorResponse) { // If attribute configuration isn't known, there is nothing else to validate - if !utils.Known(req.ConfigValue) { + if !utils.HasValue(req.ConfigValue) { return } diff --git a/apstra/blueprint/blueprint.go b/apstra/blueprint/blueprint.go index d0d4fe96..94fbf010 100644 --- a/apstra/blueprint/blueprint.go +++ b/apstra/blueprint/blueprint.go @@ -648,56 +648,56 @@ func (o *Blueprint) SetName(ctx context.Context, bpClient *apstra.TwoStageL3Clos func (o Blueprint) VersionConstraints() apiversions.Constraints { var response apiversions.Constraints - if utils.Known(o.FabricAddressing) { + if utils.HasValue(o.FabricAddressing) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("fabric_addressing"), Constraints: apiversions.Ge411, }) } - if utils.Known(o.DefaultSviL3Mtu) { + if utils.HasValue(o.DefaultSviL3Mtu) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("default_svi_l3_mtu"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.FabricMtu) { + if utils.HasValue(o.FabricMtu) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("fabric_mtu"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.JunosEvpnMaxNexthopAndInterfaceNumber) { + if utils.HasValue(o.JunosEvpnMaxNexthopAndInterfaceNumber) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("junos_evpn_max_nexthop_and_interface_number"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.JunosEvpnRoutingInstanceModeMacVrf) { + if utils.HasValue(o.JunosEvpnRoutingInstanceModeMacVrf) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("junos_evpn_routing_instance_mode_mac_vrf"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.JunosExOverlayEcmp) { + if utils.HasValue(o.JunosExOverlayEcmp) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("junos_ex_overlay_ecmp"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.JunosGracefulRestart) { + if utils.HasValue(o.JunosGracefulRestart) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("junos_graceful_restart"), Constraints: apiversions.Ge420, }) } - if utils.Known(o.OptimizeRoutingZoneFootprint) { + if utils.HasValue(o.OptimizeRoutingZoneFootprint) { response.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.Root("optimize_routing_zone_footprint"), Constraints: apiversions.Ge420, @@ -781,7 +781,7 @@ func (o *Blueprint) Request(ctx context.Context, diags *diag.Diagnostics) *apstr FabricSettings: fabricSettings, } - if utils.Known(o.FabricAddressing) { + if utils.HasValue(o.FabricAddressing) { result.FabricSettings.SpineLeafLinks = utils.FabricAddressing(ctx, o.FabricAddressing, utils.ToPtr(path.Root("fabric_addressing")), diags) if diags.HasError() { @@ -813,7 +813,7 @@ func (o *Blueprint) LoadAntiAffninityPolicy(ctx context.Context, antiAffinitypol func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) *apstra.FabricSettings { var result apstra.FabricSettings - if utils.Known(o.AntiAffinityMode) && utils.Known(o.AntiAffinityPolicy) { + if utils.HasValue(o.AntiAffinityMode) && utils.HasValue(o.AntiAffinityPolicy) { var aap AntiAffinityPolicy diags.Append(o.AntiAffinityPolicy.As(ctx, &aap, basetypes.ObjectAsOptions{})...) if diags.HasError() { @@ -836,78 +836,78 @@ func (o *Blueprint) FabricSettings(ctx context.Context, diags *diag.Diagnostics) } } - if utils.Known(o.DefaultSviL3Mtu) { + if utils.HasValue(o.DefaultSviL3Mtu) { result.DefaultSviL3Mtu = utils.ToPtr(uint16(o.DefaultSviL3Mtu.ValueInt64())) } - if utils.Known(o.EsiMacMsb) { + if utils.HasValue(o.EsiMacMsb) { result.EsiMacMsb = utils.ToPtr(uint8(o.EsiMacMsb.ValueInt64())) } - if utils.Known(o.EvpnType5Routes) { + if utils.HasValue(o.EvpnType5Routes) { result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumDisabled if o.EvpnType5Routes.ValueBool() { result.EvpnGenerateType5HostRoutes = &apstra.FeatureSwitchEnumEnabled } } - if utils.Known(o.DefaultIpLinksToGenericMtu) { + if utils.HasValue(o.DefaultIpLinksToGenericMtu) { result.ExternalRouterMtu = utils.ToPtr(uint16(o.DefaultIpLinksToGenericMtu.ValueInt64())) } - if utils.Known(o.FabricMtu) { + if utils.HasValue(o.FabricMtu) { result.FabricL3Mtu = utils.ToPtr(uint16(o.FabricMtu.ValueInt64())) } - if utils.Known(o.Ipv6Applications) { + if utils.HasValue(o.Ipv6Applications) { result.Ipv6Enabled = utils.ToPtr(o.Ipv6Applications.ValueBool()) } - if utils.Known(o.JunosEvpnMaxNexthopAndInterfaceNumber) { + if utils.HasValue(o.JunosEvpnMaxNexthopAndInterfaceNumber) { result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumDisabled if o.JunosEvpnMaxNexthopAndInterfaceNumber.ValueBool() { result.JunosEvpnMaxNexthopAndInterfaceNumber = &apstra.FeatureSwitchEnumEnabled } } - if utils.Known(o.JunosEvpnRoutingInstanceModeMacVrf) { + if utils.HasValue(o.JunosEvpnRoutingInstanceModeMacVrf) { result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumDisabled if o.JunosEvpnRoutingInstanceModeMacVrf.ValueBool() { result.JunosEvpnRoutingInstanceVlanAware = &apstra.FeatureSwitchEnumEnabled } } - if utils.Known(o.JunosExOverlayEcmp) { + if utils.HasValue(o.JunosExOverlayEcmp) { result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumDisabled if o.JunosExOverlayEcmp.ValueBool() { result.JunosExOverlayEcmp = &apstra.FeatureSwitchEnumEnabled } } - if utils.Known(o.JunosGracefulRestart) { + if utils.HasValue(o.JunosGracefulRestart) { result.JunosGracefulRestart = &apstra.FeatureSwitchEnumDisabled if o.JunosGracefulRestart.ValueBool() { result.JunosGracefulRestart = &apstra.FeatureSwitchEnumEnabled } } - if utils.Known(o.MaxEvpnRoutesCount) { + if utils.HasValue(o.MaxEvpnRoutesCount) { result.MaxEvpnRoutes = utils.ToPtr(uint32(o.MaxEvpnRoutesCount.ValueInt64())) } - if utils.Known(o.MaxExternalRoutesCount) { + if utils.HasValue(o.MaxExternalRoutesCount) { result.MaxExternalRoutes = utils.ToPtr(uint32(o.MaxExternalRoutesCount.ValueInt64())) } - if utils.Known(o.MaxFabricRoutesCount) { + if utils.HasValue(o.MaxFabricRoutesCount) { result.MaxFabricRoutes = utils.ToPtr(uint32(o.MaxFabricRoutesCount.ValueInt64())) } - if utils.Known(o.MaxMlagRoutesCount) { + if utils.HasValue(o.MaxMlagRoutesCount) { result.MaxMlagRoutes = utils.ToPtr(uint32(o.MaxMlagRoutesCount.ValueInt64())) } - if utils.Known(o.OptimizeRoutingZoneFootprint) { + if utils.HasValue(o.OptimizeRoutingZoneFootprint) { result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumDisabled if o.OptimizeRoutingZoneFootprint.ValueBool() { result.OptimiseSzFootprint = &apstra.FeatureSwitchEnumEnabled diff --git a/apstra/blueprint/datacenter_external_gateway.go b/apstra/blueprint/datacenter_external_gateway.go index 71504970..a6618096 100644 --- a/apstra/blueprint/datacenter_external_gateway.go +++ b/apstra/blueprint/datacenter_external_gateway.go @@ -242,25 +242,25 @@ func (o *DatacenterExternalGateway) Request(ctx context.Context, diags *diag.Dia } var ttl *uint8 - if utils.Known(o.Ttl) { + if utils.HasValue(o.Ttl) { t := uint8(o.Ttl.ValueInt64()) ttl = &t } var keepaliveTimer *uint16 - if utils.Known(o.KeepaliveTime) { + if utils.HasValue(o.KeepaliveTime) { t := uint16(o.KeepaliveTime.ValueInt64()) keepaliveTimer = &t } var holdtimeTimer *uint16 - if utils.Known(o.HoldTime) { + if utils.HasValue(o.HoldTime) { t := uint16(o.HoldTime.ValueInt64()) holdtimeTimer = &t } var password *string - if utils.Known(o.Password) { + if utils.HasValue(o.Password) { t := o.Password.ValueString() password = &t } diff --git a/apstra/blueprint/datacenter_generic_system_link.go b/apstra/blueprint/datacenter_generic_system_link.go index cb39af59..357df39d 100644 --- a/apstra/blueprint/datacenter_generic_system_link.go +++ b/apstra/blueprint/datacenter_generic_system_link.go @@ -125,14 +125,14 @@ func (o *DatacenterGenericSystemLink) loadApiData(ctx context.Context, in *apstr } func (o *DatacenterGenericSystemLink) getTransformId(ctx context.Context, client *apstra.TwoStageL3ClosClient, diags *diag.Diagnostics) { - if !utils.Known(o.TargetSwitchId) { + if !utils.HasValue(o.TargetSwitchId) { diags.AddError( "provider bug", "attempt to get interface transform ID without TargetSwitchId - please report this issue to the maintainers") return } - if !utils.Known(o.TargetSwitchIfName) { + if !utils.HasValue(o.TargetSwitchIfName) { diags.AddError( "provider bug", "attempt to get interface transform ID without TargetSwitchIfName - please report this issue to the maintainers") @@ -199,7 +199,7 @@ func (o *DatacenterGenericSystemLink) versionConstraintsAsGenericSystemLink(_ co var result apiversions.Constraints // can't use tags in 4.1.1 or earlier because the API endpoint we use in Read() doesn't return them - if utils.Known(o.Tags) { + if utils.HasValue(o.Tags) { result.AddAttributeConstraints(apiversions.AttributeConstraint{ Path: path.AtName("tags"), Constraints: version.MustConstraints(version.NewConstraint("> " + apiversions.Apstra411)), diff --git a/apstra/blueprint/datacenter_routing_zone.go b/apstra/blueprint/datacenter_routing_zone.go index b8e7878d..247c6e69 100644 --- a/apstra/blueprint/datacenter_routing_zone.go +++ b/apstra/blueprint/datacenter_routing_zone.go @@ -350,15 +350,15 @@ func (o *DatacenterRoutingZone) DhcpServerRequest(_ context.Context, _ *diag.Dia } func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.SecurityZoneData, diags *diag.Diagnostics) { - if !utils.Known(o.Name) { // required attribute + if !utils.HasValue(o.Name) { // required attribute o.Name = types.StringValue(data.Label) } - if !utils.Known(o.VrfName) { // computed attribute + if !utils.HasValue(o.VrfName) { // computed attribute o.VrfName = types.StringValue(data.VrfName) } - if !utils.Known(o.VlanId) { // optional + computed attribute + if !utils.HasValue(o.VlanId) { // optional + computed attribute if data.VlanId == nil { o.VlanId = types.Int64Null() } else { @@ -366,7 +366,7 @@ func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.Sec } } - if !utils.Known(o.RoutingPolicyId) { // optional + computed attribute + if !utils.HasValue(o.RoutingPolicyId) { // optional + computed attribute if data.RoutingPolicyId == "" { o.RoutingPolicyId = types.StringNull() } else { @@ -374,7 +374,7 @@ func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.Sec } } - if !utils.Known(o.Vni) { + if !utils.HasValue(o.Vni) { if data.VniId == nil { o.Vni = types.Int64Null() } else { @@ -382,7 +382,7 @@ func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.Sec } } - if !utils.Known(o.ImportRouteTargets) { + if !utils.HasValue(o.ImportRouteTargets) { if data.RtPolicy == nil || data.RtPolicy.ImportRTs == nil { o.ImportRouteTargets = types.SetNull(types.StringType) } else { @@ -390,7 +390,7 @@ func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.Sec } } - if !utils.Known(o.ExportRouteTargets) { + if !utils.HasValue(o.ExportRouteTargets) { if data.RtPolicy == nil || data.RtPolicy.ExportRTs == nil { o.ExportRouteTargets = types.SetNull(types.StringType) } else { @@ -398,7 +398,7 @@ func (o *DatacenterRoutingZone) LoadApiData(ctx context.Context, data apstra.Sec } } - if !utils.Known(o.JunosEvpnIrbMode) { + if !utils.HasValue(o.JunosEvpnIrbMode) { if data.JunosEvpnIrbMode == nil { o.JunosEvpnIrbMode = types.StringNull() } else { @@ -420,7 +420,7 @@ func (o *DatacenterRoutingZone) Query(szResultName string) *apstra.MatchQuery { nodeQuery := new(apstra.PathQuery).Node(o.szNodeQueryAttributes(szResultName)) matchQuery.Match(nodeQuery) - if utils.Known(o.RoutingPolicyId) { + if utils.HasValue(o.RoutingPolicyId) { q := new(apstra.PathQuery) q.Node([]apstra.QEEAttribute{ {Key: "name", Value: apstra.QEStringVal(szResultName)}, @@ -435,7 +435,7 @@ func (o *DatacenterRoutingZone) Query(szResultName string) *apstra.MatchQuery { matchQuery.Match(q) } - if utils.Known(o.DhcpServers) { + if utils.HasValue(o.DhcpServers) { q := new(apstra.PathQuery). Node([]apstra.QEEAttribute{ {Key: "name", Value: apstra.QEStringVal(szResultName)}, @@ -462,20 +462,20 @@ func (o *DatacenterRoutingZone) Query(szResultName string) *apstra.MatchQuery { matchQuery.Match(q) } - if utils.Known(o.ImportRouteTargets) || utils.Known(o.ExportRouteTargets) { + if utils.HasValue(o.ImportRouteTargets) || utils.HasValue(o.ExportRouteTargets) { rtPolicyNodeAttrs := []apstra.QEEAttribute{ {Key: "type", Value: apstra.QEStringVal(apstra.NodeTypeRouteTargetPolicy.String())}, {Key: "name", Value: apstra.QEStringVal("rt_policy")}, } - if utils.Known(o.ImportRouteTargets) { + if utils.HasValue(o.ImportRouteTargets) { rtPolicyNodeAttrs = append(rtPolicyNodeAttrs, apstra.QEEAttribute{ Key: "import_RTs", Value: apstra.QENone(false), }) } - if utils.Known(o.ExportRouteTargets) { + if utils.HasValue(o.ExportRouteTargets) { rtPolicyNodeAttrs = append(rtPolicyNodeAttrs, apstra.QEEAttribute{ Key: "export_RTs", Value: apstra.QENone(false), @@ -524,23 +524,23 @@ func (o *DatacenterRoutingZone) szNodeQueryAttributes(name string) []apstra.QEEA result = append(result, apstra.QEEAttribute{Key: "name", Value: apstra.QEStringVal(name)}) } - if utils.Known(o.Name) { + if utils.HasValue(o.Name) { result = append(result, apstra.QEEAttribute{Key: "label", Value: apstra.QEStringVal(o.Name.ValueString())}) } - if utils.Known(o.VrfName) { + if utils.HasValue(o.VrfName) { result = append(result, apstra.QEEAttribute{Key: "vrf_name", Value: apstra.QEStringVal(o.VrfName.ValueString())}) } - if utils.Known(o.Vni) { + if utils.HasValue(o.Vni) { result = append(result, apstra.QEEAttribute{Key: "vni_id", Value: apstra.QEIntVal(int(o.Vni.ValueInt64()))}) } - if utils.Known(o.VlanId) { + if utils.HasValue(o.VlanId) { result = append(result, apstra.QEEAttribute{Key: "vlan_id", Value: apstra.QEIntVal(int(o.VlanId.ValueInt64()))}) } - if utils.Known(o.JunosEvpnIrbMode) { + if utils.HasValue(o.JunosEvpnIrbMode) { result = append(result, apstra.QEEAttribute{Key: "junos_evpn_irb_mode", Value: apstra.QEStringVal(o.JunosEvpnIrbMode.ValueString())}) } @@ -548,13 +548,13 @@ func (o *DatacenterRoutingZone) szNodeQueryAttributes(name string) []apstra.QEEA } func (o *DatacenterRoutingZone) Read(ctx context.Context, bp *apstra.TwoStageL3ClosClient, diags *diag.Diagnostics) error { - if utils.Known(o.VlanId) && - utils.Known(o.Vni) && - utils.Known(o.DhcpServers) && - utils.Known(o.RoutingPolicyId) && - utils.Known(o.ImportRouteTargets) && - utils.Known(o.ExportRouteTargets) && - utils.Known(o.JunosEvpnIrbMode) { + if utils.HasValue(o.VlanId) && + utils.HasValue(o.Vni) && + utils.HasValue(o.DhcpServers) && + utils.HasValue(o.RoutingPolicyId) && + utils.HasValue(o.ImportRouteTargets) && + utils.HasValue(o.ExportRouteTargets) && + utils.HasValue(o.JunosEvpnIrbMode) { return nil // we are in Create() or Update() and have no need for an API call } @@ -576,7 +576,7 @@ func (o *DatacenterRoutingZone) Read(ctx context.Context, bp *apstra.TwoStageL3C o.LoadApiData(ctx, *sz.Data, diags) - if !utils.Known(o.DhcpServers) { + if !utils.HasValue(o.DhcpServers) { dhcpServerIPs, err := bp.GetSecurityZoneDhcpServers(ctx, apstra.ObjectId(o.Id.ValueString())) if err != nil { diags.AddError("failed retrieving security zone DCHP servers", err.Error()) diff --git a/apstra/blueprint/datacenter_virtual_network.go b/apstra/blueprint/datacenter_virtual_network.go index df9d9eb0..a9922cb8 100644 --- a/apstra/blueprint/datacenter_virtual_network.go +++ b/apstra/blueprint/datacenter_virtual_network.go @@ -565,7 +565,7 @@ func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diag } var vnId *apstra.VNI - if utils.Known(o.Vni) { + if utils.HasValue(o.Vni) { v := apstra.VNI(o.Vni.ValueInt64()) vnId = &v } @@ -585,13 +585,13 @@ func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diag } var ipv4Subnet, ipv6Subnet *net.IPNet - if utils.Known(o.IPv4Subnet) { + if utils.HasValue(o.IPv4Subnet) { _, ipv4Subnet, err = net.ParseCIDR(o.IPv4Subnet.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error parsing attribute ipv4_subnet value %q", o.IPv4Subnet.ValueString()), err.Error()) } } - if utils.Known(o.IPv6Subnet) { + if utils.HasValue(o.IPv6Subnet) { _, ipv6Subnet, err = net.ParseCIDR(o.IPv6Subnet.ValueString()) if err != nil { diags.AddError(fmt.Sprintf("error parsing attribute ipv6_subnet value %q", o.IPv6Subnet.ValueString()), err.Error()) @@ -599,15 +599,15 @@ func (o *DatacenterVirtualNetwork) Request(ctx context.Context, diags *diag.Diag } var ipv4Gateway, ipv6Gateway net.IP - if utils.Known(o.IPv4Gateway) { + if utils.HasValue(o.IPv4Gateway) { ipv4Gateway = net.ParseIP(o.IPv4Gateway.ValueString()) } - if utils.Known(o.IPv6Gateway) { + if utils.HasValue(o.IPv6Gateway) { ipv6Gateway = net.ParseIP(o.IPv6Gateway.ValueString()) } var l3Mtu *int - if utils.Known(o.L3Mtu) { + if utils.HasValue(o.L3Mtu) { i := int(o.L3Mtu.ValueInt64()) l3Mtu = &i } @@ -920,7 +920,7 @@ func (o DatacenterVirtualNetwork) ValidateConfigBindingsReservation(ctx context. func (o DatacenterVirtualNetwork) VersionConstraints() apiversions.Constraints { var response apiversions.Constraints - if utils.Known(o.L3Mtu) { + if utils.HasValue(o.L3Mtu) { response.AddAttributeConstraints( apiversions.AttributeConstraint{ Path: path.Root("l3_mtu"), diff --git a/apstra/blueprint/device_allocation.go b/apstra/blueprint/device_allocation.go index a8f3c79d..d1cfa451 100644 --- a/apstra/blueprint/device_allocation.go +++ b/apstra/blueprint/device_allocation.go @@ -296,13 +296,13 @@ func (o *DeviceAllocation) PopulateDataFromGraphDb(ctx context.Context, client * } switch { - case utils.Known(o.InitialInterfaceMapId) && o.DeviceKey.IsNull(): + case utils.HasValue(o.InitialInterfaceMapId) && o.DeviceKey.IsNull(): // initial_interface_map_id known, device_key not supplied o.deviceProfileNodeIdFromInterfaceMapCatalogId(ctx, client, diags) // this will clear BlueprintId on 404 case !o.DeviceKey.IsNull() && o.InitialInterfaceMapId.IsUnknown(): // device_key known, initial_interface_map_id unknown. o.deviceProfileNodeIdFromSystemIdAndDeviceKey(ctx, client, diags) // this will clear BlueprintId on 404 - case !o.DeviceKey.IsNull() && utils.Known(o.InitialInterfaceMapId): + case !o.DeviceKey.IsNull() && utils.HasValue(o.InitialInterfaceMapId): // device_key known, initial_interface_map_id known. o.deviceProfileNodeIdFromSystemIdAndDeviceKey(ctx, client, diags) // this will clear BlueprintId on 404 if o.BlueprintId.IsNull() { @@ -655,7 +655,7 @@ func (o *DeviceAllocation) deviceProfileNodeIdFromSystemIdAndDeviceKey(ctx conte } func (o DeviceAllocation) ValidateConfig(ctx context.Context, experimental types.Bool, diags *diag.Diagnostics) { - if !utils.Known(o.SystemAttributes) { + if !utils.HasValue(o.SystemAttributes) { return // nothing to validate without system_attributes } @@ -681,7 +681,7 @@ func (o DeviceAllocation) EnsureSystemIsSwitch(ctx context.Context, bp *apstra.T SetBlueprintId(bp.Id()). SetClient(bp.Client()) - if utils.Known(o.NodeId) { + if utils.HasValue(o.NodeId) { query.Node([]apstra.QEEAttribute{ apstra.NodeTypeSystem.QEEAttribute(), {Key: "id", Value: apstra.QEStringVal(o.NodeId.ValueString())}, @@ -761,7 +761,7 @@ func (o *DeviceAllocation) SetSystemAttributes(ctx context.Context, state *Devic } // did the user configure `system_attributes`? - if !utils.Known(o.SystemAttributes) { + if !utils.HasValue(o.SystemAttributes) { // `system_attributes` not configured - we may need to clear existing tags if stateSA != nil && len(stateSA.Tags.Elements()) > 0 { // tags exist. clear them. diff --git a/apstra/blueprint/device_allocation_system_attributes.go b/apstra/blueprint/device_allocation_system_attributes.go index 87c32b6d..937934a3 100644 --- a/apstra/blueprint/device_allocation_system_attributes.go +++ b/apstra/blueprint/device_allocation_system_attributes.go @@ -149,7 +149,7 @@ func (o *DeviceAllocationSystemAttributes) Get(ctx context.Context, bp *apstra.T return } - if !utils.Known(o.Tags) { + if !utils.HasValue(o.Tags) { tags, err := bp.GetNodeTags(ctx, nId) if err != nil { diags.AddError(fmt.Sprintf("failed to readtags from node %s", nodeId), err.Error()) @@ -160,7 +160,7 @@ func (o *DeviceAllocationSystemAttributes) Get(ctx context.Context, bp *apstra.T } func (o *DeviceAllocationSystemAttributes) getAsn(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if utils.Known(o.Asn) { + if utils.HasValue(o.Asn) { return } @@ -199,7 +199,7 @@ func (o *DeviceAllocationSystemAttributes) getAsn(ctx context.Context, bp *apstr } func (o *DeviceAllocationSystemAttributes) getLoopback0Addresses(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if utils.Known(o.LoopbackIpv4) && utils.Known(o.LoopbackIpv6) { + if utils.HasValue(o.LoopbackIpv4) && utils.HasValue(o.LoopbackIpv6) { return } @@ -235,7 +235,7 @@ func (o *DeviceAllocationSystemAttributes) getLoopback0Addresses(ctx context.Con return // no loopback IP addresses found in domain node } - if !utils.Known(o.LoopbackIpv4) { + if !utils.HasValue(o.LoopbackIpv4) { o.LoopbackIpv4 = cidrtypes.NewIPv4PrefixNull() if loopbackNode.IPv4Addr != nil && len(*loopbackNode.IPv4Addr) != 0 { _, _, err := net.ParseCIDR(*loopbackNode.IPv4Addr) @@ -249,7 +249,7 @@ func (o *DeviceAllocationSystemAttributes) getLoopback0Addresses(ctx context.Con } } - if !utils.Known(o.LoopbackIpv6) { + if !utils.HasValue(o.LoopbackIpv6) { o.LoopbackIpv6 = cidrtypes.NewIPv6PrefixNull() if loopbackNode.IPv6Addr != nil && len(*loopbackNode.IPv6Addr) != 0 { _, _, err := net.ParseCIDR(*loopbackNode.IPv6Addr) @@ -265,7 +265,7 @@ func (o *DeviceAllocationSystemAttributes) getLoopback0Addresses(ctx context.Con } func (o *DeviceAllocationSystemAttributes) getProperties(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if utils.Known(o.DeployMode) && utils.Known(o.Hostname) && utils.Known(o.Name) { + if utils.HasValue(o.DeployMode) && utils.HasValue(o.Hostname) && utils.HasValue(o.Name) { return } @@ -288,13 +288,13 @@ func (o *DeviceAllocationSystemAttributes) getProperties(ctx context.Context, bp return } - if !utils.Known(o.DeployMode) { + if !utils.HasValue(o.DeployMode) { o.DeployMode = types.StringValue(utils.StringersToFriendlyString(deployMode)) } - if !utils.Known(o.Hostname) { + if !utils.HasValue(o.Hostname) { o.Hostname = types.StringValue(node.Hostname) } - if !utils.Known(o.Name) { + if !utils.HasValue(o.Name) { o.Name = types.StringValue(node.Label) } } @@ -318,7 +318,7 @@ func (o *DeviceAllocationSystemAttributes) Set(ctx context.Context, state *Devic } func (o *DeviceAllocationSystemAttributes) setAsn(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if !utils.Known(o.Asn) { + if !utils.HasValue(o.Asn) { return } @@ -365,7 +365,7 @@ func (o *DeviceAllocationSystemAttributes) setAsn(ctx context.Context, bp *apstr } func (o *DeviceAllocationSystemAttributes) setLoopbacks(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if !utils.Known(o.LoopbackIpv4) && !utils.Known(o.LoopbackIpv6) { + if !utils.HasValue(o.LoopbackIpv4) && !utils.HasValue(o.LoopbackIpv6) { return } @@ -375,13 +375,13 @@ func (o *DeviceAllocationSystemAttributes) setLoopbacks(ctx context.Context, bp return } - if len(rawJson) == 0 && utils.Known(o.LoopbackIpv4) { + if len(rawJson) == 0 && utils.HasValue(o.LoopbackIpv4) { diags.AddAttributeError( path.Root("system_attributes").AtName("loopback_ipv4"), "Cannot set loopback address", fmt.Sprintf("system %q has no associated loopback %d node -- is it a spine or leaf switch?", nodeId, idx)) } - if len(rawJson) == 0 && utils.Known(o.LoopbackIpv6) { + if len(rawJson) == 0 && utils.HasValue(o.LoopbackIpv6) { diags.AddAttributeError( path.Root("system_attributes").AtName("loopback_ipv6"), "Cannot set loopback address", @@ -424,11 +424,11 @@ func (o *DeviceAllocationSystemAttributes) setLoopbacks(ctx context.Context, bp } func (o *DeviceAllocationSystemAttributes) setProperties(ctx context.Context, bp *apstra.TwoStageL3ClosClient, nodeId apstra.ObjectId, diags *diag.Diagnostics) { - if !utils.Known(o.Name) && !utils.Known(o.Hostname) && !utils.Known(o.DeployMode) { + if !utils.HasValue(o.Name) && !utils.HasValue(o.Hostname) && !utils.HasValue(o.DeployMode) { return } - if utils.Known(o.DeployMode) { + if utils.HasValue(o.DeployMode) { var deployMode apstra.DeployMode err := utils.ApiStringerFromFriendlyString(&deployMode, o.DeployMode.ValueString()) if err != nil { diff --git a/apstra/blueprint/ip_link_addressing.go b/apstra/blueprint/ip_link_addressing.go index 5bb17a3f..a57a76f9 100644 --- a/apstra/blueprint/ip_link_addressing.go +++ b/apstra/blueprint/ip_link_addressing.go @@ -182,7 +182,7 @@ func requestEndpoint(v4type, v6type types.String, v4addr cidrtypes.IPv4Prefix, v } func (o IpLinkAddressing) Request(_ context.Context, diags *diag.Diagnostics) map[apstra.ObjectId]apstra.TwoStageL3ClosSubinterface { - if !utils.Known(o.SwitchIntfId) || !utils.Known(o.GenericIntfId) { + if !utils.HasValue(o.SwitchIntfId) || !utils.HasValue(o.GenericIntfId) { diags.AddError( constants.ErrProviderBug, fmt.Sprintf("attempt to generate ip link addressing with unknown interface ID\n"+ diff --git a/apstra/blueprint/node_system_attributes.go b/apstra/blueprint/node_system_attributes.go index a3f8ea67..9d2a8873 100644 --- a/apstra/blueprint/node_system_attributes.go +++ b/apstra/blueprint/node_system_attributes.go @@ -116,27 +116,27 @@ func (o NodeTypeSystemAttributes) DataSourceAttributesAsFilter() map[string]data func (o NodeTypeSystemAttributes) QEEAttributes() []apstra.QEEAttribute { var result []apstra.QEEAttribute - if utils.Known(o.Hostname) { + if utils.HasValue(o.Hostname) { result = append(result, apstra.QEEAttribute{Key: "hostname", Value: apstra.QEStringVal(o.Hostname.ValueString())}) } - if utils.Known(o.Id) { + if utils.HasValue(o.Id) { result = append(result, apstra.QEEAttribute{Key: "id", Value: apstra.QEStringVal(o.Id.ValueString())}) } - if utils.Known(o.Label) { + if utils.HasValue(o.Label) { result = append(result, apstra.QEEAttribute{Key: "label", Value: apstra.QEStringVal(o.Label.ValueString())}) } - if utils.Known(o.Role) { + if utils.HasValue(o.Role) { result = append(result, apstra.QEEAttribute{Key: "role", Value: apstra.QEStringVal(o.Role.ValueString())}) } - if utils.Known(o.SystemId) { + if utils.HasValue(o.SystemId) { result = append(result, apstra.QEEAttribute{Key: "system_id", Value: apstra.QEStringVal(o.SystemId.ValueString())}) } - if utils.Known(o.SystemType) { + if utils.HasValue(o.SystemType) { result = append(result, apstra.QEEAttribute{Key: "system_type", Value: apstra.QEStringVal(o.SystemType.ValueString())}) } @@ -145,7 +145,7 @@ func (o NodeTypeSystemAttributes) QEEAttributes() []apstra.QEEAttribute { func (o NodeTypeSystemAttributes) query(ctx context.Context, diags *diag.Diagnostics) *apstra.MatchQuery { var tagIds []string - if utils.Known(o.TagIds) { + if utils.HasValue(o.TagIds) { diags.Append(o.TagIds.ElementsAs(ctx, &tagIds, false)...) if diags.HasError() { return nil diff --git a/apstra/blueprint/nodes_system.go b/apstra/blueprint/nodes_system.go index 02118bd3..10c9ce3e 100644 --- a/apstra/blueprint/nodes_system.go +++ b/apstra/blueprint/nodes_system.go @@ -90,9 +90,9 @@ func (o *NodesTypeSystem) ReadFromApi(ctx context.Context, client *apstra.Client // we're always going to perform at least one query, but we keep 'em as a slice var queries []apstra.MatchQuery switch { - case utils.Known(o.Filter): // one query, because the user specified 'filter' (deprecated) + case utils.HasValue(o.Filter): // one query, because the user specified 'filter' (deprecated) var filter NodeTypeSystemAttributes - if utils.Known(o.Filter) { + if utils.HasValue(o.Filter) { diags.Append(o.Filter.As(ctx, &filter, basetypes.ObjectAsOptions{})...) if diags.HasError() { return @@ -103,9 +103,9 @@ func (o *NodesTypeSystem) ReadFromApi(ctx context.Context, client *apstra.Client if diags.HasError() { return } - case utils.Known(o.Filters): // many queries, because the user specified 'filters' + case utils.HasValue(o.Filters): // many queries, because the user specified 'filters' var filters []NodeTypeSystemAttributes - if utils.Known(o.Filters) { + if utils.HasValue(o.Filters) { diags.Append(o.Filters.ElementsAs(ctx, &filters, false)...) if diags.HasError() { return diff --git a/apstra/blueprint/vn_binding.go b/apstra/blueprint/vn_binding.go index 45b6bf0a..7d74bccb 100644 --- a/apstra/blueprint/vn_binding.go +++ b/apstra/blueprint/vn_binding.go @@ -81,7 +81,7 @@ func (o VnBinding) ResourceAttributes() map[string]resourceSchema.Attribute { func (o VnBinding) Request(ctx context.Context, leafId string, diags *diag.Diagnostics) *apstra.VnBinding { var vlanId *apstra.Vlan - if utils.Known(o.VlanId) { + if utils.HasValue(o.VlanId) { v := apstra.Vlan(o.VlanId.ValueInt64()) vlanId = &v } diff --git a/apstra/blueprint/vn_binding_constructor.go b/apstra/blueprint/vn_binding_constructor.go index dd5242e2..8474c8fd 100644 --- a/apstra/blueprint/vn_binding_constructor.go +++ b/apstra/blueprint/vn_binding_constructor.go @@ -60,7 +60,7 @@ func (o VnBindingConstructor) DataSourceAttributes() map[string]dataSourceSchema func (o *VnBindingConstructor) Compute(ctx context.Context, bpClient *apstra.TwoStageL3ClosClient, diags *diag.Diagnostics) { // only one VLAN per constructor; get it in the expected form var vlanId *apstra.Vlan - if utils.Known(o.VlanId) { + if utils.HasValue(o.VlanId) { v := apstra.Vlan(o.VlanId.ValueInt64()) vlanId = &v } diff --git a/apstra/data_source_datacenter_ct_custom_static_route.go b/apstra/data_source_datacenter_ct_custom_static_route.go index d80403e7..d3e17bf8 100644 --- a/apstra/data_source_datacenter_ct_custom_static_route.go +++ b/apstra/data_source_datacenter_ct_custom_static_route.go @@ -37,7 +37,7 @@ func (o *dataSourceDatacenterCtCustomStaticRoute) ValidateConfig(ctx context.Con } // We're checking if these attributes are incompatible. If either are null/unknown, there's nothing to do. - if !utils.Known(config.Network) || !utils.Known(config.NextHop) { + if !utils.HasValue(config.Network) || !utils.HasValue(config.NextHop) { return } diff --git a/apstra/design/template_pod_based.go b/apstra/design/template_pod_based.go index 0f4a223a..d8f9f6a0 100644 --- a/apstra/design/template_pod_based.go +++ b/apstra/design/template_pod_based.go @@ -156,7 +156,7 @@ func (o *TemplatePodBased) Request(ctx context.Context, diags *diag.Diagnostics) } var fabricAddressingPolicy *apstra.TemplateFabricAddressingPolicy410Only - if utils.Known(o.FabricAddressing) { + if utils.HasValue(o.FabricAddressing) { var addressingScheme apstra.AddressingScheme err = addressingScheme.FromString(o.FabricAddressing.ValueString()) if err != nil { diff --git a/apstra/design/template_rack_based.go b/apstra/design/template_rack_based.go index 0405a7e2..d224b24b 100644 --- a/apstra/design/template_rack_based.go +++ b/apstra/design/template_rack_based.go @@ -273,7 +273,7 @@ func (o *TemplateRackBased) Request(ctx context.Context, diags *diag.Diagnostics } var fabricAddressingPolicy *apstra.TemplateFabricAddressingPolicy410Only - if utils.Known(o.FabricAddressing) { + if utils.HasValue(o.FabricAddressing) { var addressingScheme apstra.AddressingScheme err = addressingScheme.FromString(o.FabricAddressing.ValueString()) if err != nil { diff --git a/apstra/resource_datacenter_device_allocation.go b/apstra/resource_datacenter_device_allocation.go index a0c1cb56..78774662 100644 --- a/apstra/resource_datacenter_device_allocation.go +++ b/apstra/resource_datacenter_device_allocation.go @@ -124,7 +124,7 @@ func (o *resourceDeviceAllocation) Create(ctx context.Context, req resource.Crea } // Deprecated attribute in use? - if utils.Known(plan.DeployMode) { + if utils.HasValue(plan.DeployMode) { // validators ensure that system_attributes object has been omitted. instantiate a fresh one and copy the deploy mode in there sa, d := types.ObjectValueFrom(ctx, blueprint.DeviceAllocationSystemAttributes{}.AttrTypes(), blueprint.DeviceAllocationSystemAttributes{ DeployMode: plan.DeployMode, @@ -274,7 +274,7 @@ func (o *resourceDeviceAllocation) Update(ctx context.Context, req resource.Upda } // Deprecated attribute in use? - if utils.Known(plan.DeployMode) { + if utils.HasValue(plan.DeployMode) { // validators ensure that system_attributes object has been omitted. instantiate a fresh one and copy the deploy mode in there sa, d := types.ObjectValueFrom(ctx, blueprint.DeviceAllocationSystemAttributes{}.AttrTypes(), basetypes.ObjectAsOptions{}) resp.Diagnostics.Append(d...) diff --git a/apstra/resource_datacenter_routing_zone.go b/apstra/resource_datacenter_routing_zone.go index 7a2f9867..5ebfd2bb 100644 --- a/apstra/resource_datacenter_routing_zone.go +++ b/apstra/resource_datacenter_routing_zone.go @@ -266,8 +266,8 @@ func (o *resourceDatacenterRoutingZone) Update(ctx context.Context, req resource } // set new "prior" markers - plan.HadPriorVlanIdConfig = types.BoolValue(utils.Known(plan.VlanId)) - plan.HadPriorVniConfig = types.BoolValue(utils.Known(plan.Vni)) + plan.HadPriorVlanIdConfig = types.BoolValue(utils.HasValue(plan.VlanId)) + plan.HadPriorVniConfig = types.BoolValue(utils.HasValue(plan.Vni)) // send the update err = bp.UpdateSecurityZone(ctx, apstra.ObjectId(plan.Id.ValueString()), request) diff --git a/apstra/utils/attr_value_known.go b/apstra/utils/attr_has_value.go similarity index 77% rename from apstra/utils/attr_value_known.go rename to apstra/utils/attr_has_value.go index d9cc9bcd..450317a3 100644 --- a/apstra/utils/attr_value_known.go +++ b/apstra/utils/attr_has_value.go @@ -2,6 +2,6 @@ package utils import "github.com/hashicorp/terraform-plugin-framework/attr" -func Known(v attr.Value) bool { +func HasValue(v attr.Value) bool { return !v.IsUnknown() && !v.IsNull() } diff --git a/apstra/utils/strings.go b/apstra/utils/strings.go index 0ff7ca06..199617f2 100644 --- a/apstra/utils/strings.go +++ b/apstra/utils/strings.go @@ -10,7 +10,7 @@ import ( ) func FabricAddressing(_ context.Context, s types.String, path *path.Path, diags *diag.Diagnostics) *apstra.AddressingScheme { - if !Known(s) { + if !HasValue(s) { return nil }