Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CT resource batch_id plan modifiers to handle unknown children #1023

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading