Skip to content

fix: prevent inconsistent result error on update with ignore_all_server_changes - #359

Open
maxtwardowski wants to merge 1 commit into
Mastercard:mainfrom
maxtwardowski:fix/ignore-all-server-changes-update
Open

maxtwardowski wants to merge 1 commit into
Mastercard:mainfrom
maxtwardowski:fix/ignore-all-server-changes-update

Conversation

@maxtwardowski

Copy link
Copy Markdown

Summary

Update does not respect ignore_all_server_changes, causing "Provider produced inconsistent result after apply" when update_data changes a field that the server echoes back.

This is the same class of bug as #356 (which fixes ignore_server_additions), but for the ignore_all_server_changes code path.

Problem

ModifyPlan correctly preserves api_data and api_response from prior state when ignore_all_server_changes = true — telling Terraform these computed attributes won't change during apply.

However, Update unconditionally calls setResourceModelData, which overwrites api_data and api_response with values from the server response (either from the write response or the subsequent GET). When the update changes a field (e.g. name), the server returns the new value, creating a mismatch between what the plan promised and what the apply produced:

Error: Provider produced inconsistent result after apply

.api_data["name"]: was cty.StringVal("old"), but now cty.StringVal("new").

This makes ignore_all_server_changes incompatible with update_data for any field the server echoes back.

Reproduction

resource "restapi_object" "example" {
  path                      = "/api/resources"
  update_method             = "PATCH"
  ignore_all_server_changes = true

  data = jsonencode({
    name       = var.name
    secret_key = var.secret  # sensitive, only needed on creation
  })

  update_data = jsonencode({
    name = var.name
  })

  lifecycle {
    ignore_changes = [data]
  }
}
  1. terraform apply — creates the resource successfully.
  2. Change var.name and run terraform apply — plan correctly shows only update_data changing.
  3. Apply fails with "Provider produced inconsistent result".

Fix

In Update, when ignore_all_server_changes is true, preserve api_data and api_response from prior state instead of overwriting them from the server response. This mirrors the existing pattern in ModifyPlan.

Test plan

  • Added TestAccRestApiObject_IgnoreAllServerChanges_Update — creates a resource with ignore_all_server_changes = true and update_data, then changes update_data in a second step. Without the fix, step 2 fails with "Provider produced inconsistent result".
  • Existing TestAccRestApiObject_IgnoreAllServerChanges still passes.
  • Full test suite passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant