From f8dcb7971cade7b44e4daad5c9051625ced0ed9a Mon Sep 17 00:00:00 2001 From: Chris Marget Date: Wed, 22 Jan 2025 13:50:49 -0500 Subject: [PATCH] update batch_id plan modifier to handle unknown children --- .../primitives/bgp_peering_generic_sytem.go | 8 +++++--- .../primitives/bgp_peering_ip_endpoint.go | 8 +++++--- .../primitives/dynamic_bgp_peering.go | 8 +++++--- .../connectivity_templates/primitives/ip_link.go | 11 ++++++++--- .../primitives/virtual_network_single.go | 9 ++++++--- 5 files changed, 29 insertions(+), 15 deletions(-) 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 c5f71eb3..fe0b99b2 100644 --- a/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go +++ b/apstra/blueprint/connectivity_templates/primitives/bgp_peering_generic_sytem.go @@ -375,9 +375,11 @@ func (o bgpPeeringGenericSystemBatchIdPlanModifier) PlanModifyString(ctx context planHasChildren := len(plan.RoutingPolicies.Elements()) > 0 + planChildrenUnknown := plan.RoutingPolicies.IsUnknown() + // are we a new object? if stateDoesNotExist { - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() @@ -387,14 +389,14 @@ func (o bgpPeeringGenericSystemBatchIdPlanModifier) PlanModifyString(ctx context stateHasChildren := len(state.RoutingPolicies.Elements()) > 0 - if planHasChildren == stateHasChildren { + if (planHasChildren || planChildrenUnknown) == stateHasChildren { // state and plan agree about whether a batch ID is required. Reuse the old value. resp.PlanValue = req.StateValue return } // We've either gained our first, or lost our last child primitive. Set the plan value accordingly. - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() diff --git a/apstra/blueprint/connectivity_templates/primitives/bgp_peering_ip_endpoint.go b/apstra/blueprint/connectivity_templates/primitives/bgp_peering_ip_endpoint.go index a1fc6622..eab2cb9f 100644 --- a/apstra/blueprint/connectivity_templates/primitives/bgp_peering_ip_endpoint.go +++ b/apstra/blueprint/connectivity_templates/primitives/bgp_peering_ip_endpoint.go @@ -340,9 +340,11 @@ func (o bgpPeeringIpEndpointBatchIdPlanModifier) PlanModifyString(ctx context.Co planHasChildren := len(plan.RoutingPolicies.Elements()) > 0 + planChildrenUnknown := plan.RoutingPolicies.IsUnknown() + // are we a new object? if stateDoesNotExist { - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() @@ -352,14 +354,14 @@ func (o bgpPeeringIpEndpointBatchIdPlanModifier) PlanModifyString(ctx context.Co stateHasChildren := len(state.RoutingPolicies.Elements()) > 0 - if planHasChildren == stateHasChildren { + if (planHasChildren || planChildrenUnknown) == stateHasChildren { // state and plan agree about whether a batch ID is required. Reuse the old value. resp.PlanValue = req.StateValue return } // We've either gained our first, or lost our last child primitive. Set the plan value accordingly. - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() diff --git a/apstra/blueprint/connectivity_templates/primitives/dynamic_bgp_peering.go b/apstra/blueprint/connectivity_templates/primitives/dynamic_bgp_peering.go index 8f6f1ad5..bbf1ff9a 100644 --- a/apstra/blueprint/connectivity_templates/primitives/dynamic_bgp_peering.go +++ b/apstra/blueprint/connectivity_templates/primitives/dynamic_bgp_peering.go @@ -351,9 +351,11 @@ func (o dynamicBgpPeeringBatchIdPlanModifier) PlanModifyString(ctx context.Conte planHasChildren := len(plan.RoutingPolicies.Elements()) > 0 + planChildrenUnknown := plan.RoutingPolicies.IsUnknown() + // are we a new object? if stateDoesNotExist { - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() @@ -363,14 +365,14 @@ func (o dynamicBgpPeeringBatchIdPlanModifier) PlanModifyString(ctx context.Conte stateHasChildren := len(state.RoutingPolicies.Elements()) > 0 - if planHasChildren == stateHasChildren { + if (planHasChildren || planChildrenUnknown) == stateHasChildren { // state and plan agree about whether a batch ID is required. Reuse the old value. resp.PlanValue = req.StateValue return } // We've either gained our first, or lost our last child primitive. Set the plan value accordingly. - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() diff --git a/apstra/blueprint/connectivity_templates/primitives/ip_link.go b/apstra/blueprint/connectivity_templates/primitives/ip_link.go index 4119ef20..8387634b 100644 --- a/apstra/blueprint/connectivity_templates/primitives/ip_link.go +++ b/apstra/blueprint/connectivity_templates/primitives/ip_link.go @@ -352,9 +352,14 @@ func (o ipLinkBatchIdPlanModifier) PlanModifyString(ctx context.Context, req pla len(plan.DynamicBgpPeerings.Elements())+ len(plan.StaticRoutes.Elements()) > 0 + planChildrenUnknown := plan.BgpPeeringGenericSystems.IsUnknown() || + plan.BgpPeeringIpEndpoints.IsUnknown() || + plan.DynamicBgpPeerings.IsUnknown() || + plan.StaticRoutes.IsUnknown() + // are we a new object? if stateDoesNotExist { - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() @@ -367,14 +372,14 @@ func (o ipLinkBatchIdPlanModifier) PlanModifyString(ctx context.Context, req pla len(state.DynamicBgpPeerings.Elements())+ len(state.StaticRoutes.Elements()) > 0 - if planHasChildren == stateHasChildren { + if (planHasChildren || planChildrenUnknown) == stateHasChildren { // state and plan agree about whether a batch ID is required. Reuse the old value. resp.PlanValue = req.StateValue return } // We've either gained our first, or lost our last child primitive. Set the plan value accordingly. - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() diff --git a/apstra/blueprint/connectivity_templates/primitives/virtual_network_single.go b/apstra/blueprint/connectivity_templates/primitives/virtual_network_single.go index 74911b34..88d9d206 100644 --- a/apstra/blueprint/connectivity_templates/primitives/virtual_network_single.go +++ b/apstra/blueprint/connectivity_templates/primitives/virtual_network_single.go @@ -226,9 +226,12 @@ func (o virtualNetworkSingleBatchIdPlanModifier) PlanModifyString(ctx context.Co planHasChildren := len(plan.BgpPeeringGenericSystems.Elements())+ len(plan.StaticRoutes.Elements()) > 0 + planChildrenUnknown := plan.BgpPeeringGenericSystems.IsUnknown() || + plan.StaticRoutes.IsUnknown() + // are we a new object? if stateDoesNotExist { - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull() @@ -239,14 +242,14 @@ func (o virtualNetworkSingleBatchIdPlanModifier) PlanModifyString(ctx context.Co stateHasChildren := len(state.BgpPeeringGenericSystems.Elements())+ len(state.StaticRoutes.Elements()) > 0 - if planHasChildren == stateHasChildren { + if (planHasChildren || planChildrenUnknown) == stateHasChildren { // state and plan agree about whether a batch ID is required. Reuse the old value. resp.PlanValue = req.StateValue return } // We've either gained our first, or lost our last child primitive. Set the plan value accordingly. - if planHasChildren { + if planHasChildren || planChildrenUnknown { resp.PlanValue = types.StringUnknown() } else { resp.PlanValue = types.StringNull()