Skip to content

Commit

Permalink
Merge pull request #1023 from Juniper/issue-1012-with-unknown-child-p…
Browse files Browse the repository at this point in the history
…rimitives

Update CT resource `batch_id` plan modifiers to handle `unknown` children
  • Loading branch information
chrismarget-j authored Jan 22, 2025
2 parents 597198f + f8dcb79 commit 92c1d19
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions apstra/blueprint/connectivity_templates/primitives/ip_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 92c1d19

Please sign in to comment.