@@ -226,7 +226,36 @@ func (r *requestConditionResource) Create(ctx context.Context, req resource.Crea
226226 }
227227 }
228228
229+ // The API may ignore the priority field on create and return a default
230+ // value (e.g. always 0). Save the planned priority so we can restore it
231+ // after applying the API response to state, since even the follow-up
232+ // PATCH response returns 0 for this field.
233+ plannedPriority := data .Priority
234+
235+ // If the planned priority differs from what the API returned, issue a
236+ // follow-up PATCH to attempt to set the correct value server-side.
237+ if ! plannedPriority .IsNull () && plannedPriority .ValueInt32 () != requestConditionResp .GetPriority () {
238+ _ , _ , err = r .OktaGovernanceClient .OktaGovernanceSDKClient ().
239+ RequestConditionsAPI .UpdateResourceRequestConditionV2 (ctx ,
240+ data .ResourceId .ValueString (),
241+ requestConditionResp .GetId ()).RequestConditionPatchable (createRequestConditionPatch (data )).Execute ()
242+ if err != nil {
243+ resp .Diagnostics .AddError (
244+ "Error setting priority on Request condition" ,
245+ "Could not update priority after creation: " + err .Error (),
246+ )
247+ return
248+ }
249+ }
250+
229251 resp .Diagnostics .Append (applyRequestConditionToState (ctx , & data , requestConditionResp )... )
252+
253+ // Restore the planned priority: the API always returns 0 for this field,
254+ // even after a successful PATCH, so we preserve the planned value to
255+ // avoid a "Provider produced inconsistent result after apply" error.
256+ if ! plannedPriority .IsNull () && data .Priority .ValueInt32 () == 0 && plannedPriority .ValueInt32 () != 0 {
257+ data .Priority = plannedPriority
258+ }
230259 if resp .Diagnostics .HasError () {
231260 return
232261 }
@@ -245,6 +274,11 @@ func (r *requestConditionResource) Read(ctx context.Context, req resource.ReadRe
245274 return
246275 }
247276
277+ // Save the prior-state priority: the API always returns 0 for this field
278+ // regardless of what was configured, so we preserve the known priority to
279+ // avoid a spurious non-empty plan after apply.
280+ priorPriority := data .Priority
281+
248282 // Read API call logic
249283 readRequestConditionResp , httpResp , err := r .OktaGovernanceClient .OktaGovernanceSDKClient ().RequestConditionsAPI .GetResourceRequestConditionV2 (ctx , data .ResourceId .ValueString (), data .Id .ValueString ()).Execute ()
250284 if err != nil {
@@ -265,6 +299,13 @@ func (r *requestConditionResource) Read(ctx context.Context, req resource.ReadRe
265299 if resp .Diagnostics .HasError () {
266300 return
267301 }
302+
303+ // Restore the prior-state priority when the API returns 0 but the
304+ // configuration had a non-zero value.
305+ if ! priorPriority .IsNull () && data .Priority .ValueInt32 () == 0 && priorPriority .ValueInt32 () != 0 {
306+ data .Priority = priorPriority
307+ }
308+
268309 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
269310}
270311
@@ -283,6 +324,10 @@ func (r *requestConditionResource) Update(ctx context.Context, req resource.Upda
283324 return
284325 }
285326
327+ // Save planned priority before the API call: the update API also returns
328+ // 0 for priority in the response, so we preserve the planned value.
329+ plannedPriority := data .Priority
330+
286331 // Update API call logic
287332 ctx = context .WithValue (ctx , api .RetryOnStatusCodes , []int {http .StatusConflict })
288333 updatedRequestCondition , _ , err := r .OktaGovernanceClient .OktaGovernanceSDKClient ().RequestConditionsAPI .UpdateResourceRequestConditionV2 (ctx , data .ResourceId .ValueString (), state .Id .ValueString ()).RequestConditionPatchable (createRequestConditionPatch (data )).Execute ()
@@ -333,6 +378,12 @@ func (r *requestConditionResource) Update(ctx context.Context, req resource.Upda
333378 return
334379 }
335380
381+ // Restore the planned priority: the update API also returns 0 for this
382+ // field, so we preserve the planned value to keep state consistent.
383+ if ! plannedPriority .IsNull () && data .Priority .ValueInt32 () == 0 && plannedPriority .ValueInt32 () != 0 {
384+ data .Priority = plannedPriority
385+ }
386+
336387 // Save Data into Terraform state
337388 resp .Diagnostics .Append (resp .State .Set (ctx , & data )... )
338389}
0 commit comments