Skip to content

refactor: Updates advanced_cluster tpf plan_modifier auto_scaling removed logic #3213

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

Closed
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
12 changes: 0 additions & 12 deletions internal/service/advancedclustertpf/plan_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,6 @@ func AdjustRegionConfigsChildren(ctx context.Context, diags *diag.Diagnostics, s
}
planRegionConfigsTF[j].AnalyticsSpecs = objType
}

// don't use auto_scaling or analytics_auto_scaling from state if it's not enabled as it doesn't need to be present in Update request payload
stateAutoScaling := TFModelObject[TFAutoScalingModel](ctx, stateRegionConfigsTF[j].AutoScaling)
planAutoScaling := TFModelObject[TFAutoScalingModel](ctx, planRegionConfigsTF[j].AutoScaling)
if planAutoScaling == nil && stateAutoScaling != nil && (stateAutoScaling.ComputeEnabled.ValueBool() || stateAutoScaling.DiskGBEnabled.ValueBool()) {
planRegionConfigsTF[j].AutoScaling = stateRegionConfigsTF[j].AutoScaling
}
stateAnalyticsAutoScaling := TFModelObject[TFAutoScalingModel](ctx, stateRegionConfigsTF[j].AnalyticsAutoScaling)
planAnalyticsAutoScaling := TFModelObject[TFAutoScalingModel](ctx, planRegionConfigsTF[j].AnalyticsAutoScaling)
if planAnalyticsAutoScaling == nil && stateAnalyticsAutoScaling != nil && (stateAnalyticsAutoScaling.ComputeEnabled.ValueBool() || stateAnalyticsAutoScaling.DiskGBEnabled.ValueBool()) {
planRegionConfigsTF[j].AnalyticsAutoScaling = stateRegionConfigsTF[j].AnalyticsAutoScaling
}
}
listRegionConfigs, diagsLocal := types.ListValueFrom(ctx, RegionConfigsObjType, planRegionConfigsTF)
diags.Append(diagsLocal...)
Expand Down
12 changes: 11 additions & 1 deletion internal/service/advancedclustertpf/plan_modifier2.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@ import (
)

var attributePlanModifiers = map[string]customplanmodifier.UnknownReplacementCall[PlanModifyResourceInfo]{
"mongo_db_version": mongoDBVersionReplaceUnknown,
"mongo_db_version": mongoDBVersionReplaceUnknown,
"auto_scaling": autoScalingReplaceUnknown,
"analytics_auto_scaling": autoScalingReplaceUnknown,
// TODO: Add the other computed attributes
}

func autoScalingReplaceUnknown(ctx context.Context, state customplanmodifier.ParsedAttrValue, req *customplanmodifier.UnknownReplacementRequest[PlanModifyResourceInfo]) attr.Value {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only called if plan is unknown, right?

nice the new approach, less verbose and easier to understand

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct 👍

// don't use auto_scaling or analytics_auto_scaling from state if it's not enabled as it doesn't need to be present in Update request payload
if req.Info.AutoScalingComputedUsed || req.Info.AutoScalingDiskUsed {
return state.AsObject()
}
return req.Unknown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic to affect other elements when autoscale is enabled, e.g. keepUnkownFuncWithNonEmptyAutoScaling is not implemented yet, is that correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, not implemented. Will be done in CLOUDP-308783

}

func mongoDBVersionReplaceUnknown(ctx context.Context, state customplanmodifier.ParsedAttrValue, req *customplanmodifier.UnknownReplacementRequest[PlanModifyResourceInfo]) attr.Value {
if req.Changes.AttributeChanged("mongo_db_major_version") {
return req.Unknown
Expand Down
Loading