Skip to content

Commit cfe9d9d

Browse files
authored
chore: Simplifies Unknown detection (#3137)
* check that they behave the same * remove HasUnknowns * keep tests
1 parent 9b217fe commit cfe9d9d

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

internal/common/schemafunc/plan_modifier_state_for_unknown_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type hasUnknownsPanicMissingMethod struct {
4242
Field missingMethodType
4343
}
4444

45+
// TestHasUnknown is kept even if HasUnknowns is not used so we can test isUnknown that is also used in CopyFromUnknown
4546
func TestHasUnknown(t *testing.T) {
4647
tests := map[string]struct {
4748
input any

internal/service/advancedclustertpf/resource.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
1818
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
19-
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/schemafunc"
2019
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/update"
2120
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
2221
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/flexcluster"
@@ -99,7 +98,7 @@ type rs struct {
9998
// 1. UseStateForUnknown always copies the state for unknown values. However, that leads to `Error: Provider produced inconsistent result after apply` in some cases (see implementation below).
10099
// 2. Adding the different UseStateForUnknown is very verbose.
101100
func (r *rs) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
102-
if req.Plan.Raw.IsNull() || req.State.Raw.IsNull() { // Return early unless it is an Update
101+
if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() || req.Plan.Raw.IsFullyKnown() { // Return early unless it is an Update
103102
return
104103
}
105104
var plan, state TFModel
@@ -109,10 +108,8 @@ func (r *rs) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, res
109108
if diags.HasError() {
110109
return
111110
}
112-
if !schemafunc.HasUnknowns(&plan) { // Don't do anything if there are no unknowns, this happens in Read
113-
return
114-
}
115-
useStateForUnknowns(ctx, diags, &state, &plan) // Do only for Update
111+
112+
useStateForUnknowns(ctx, diags, &state, &plan)
116113
if diags.HasError() {
117114
return
118115
}

0 commit comments

Comments
 (0)