Terraform plan detects false changes, and doesn't show it in the output

Hello, I’m developing a Terraform provider and I’ve been dealing with a very weird behavior in two of my Resources. I’m gonna talk about one of them but the issue is the same in the other one.

I have a Resource with an attribute called auto_scale, which is a SingleNestedAttribute and it has two children, max and min, both Int64Attributes.
The auto_scale attribute, which is the “parent” object attribute, is Optional and Computed and it has the UseStateForUnknown modifier.

When creating the Resource, I DON’T specify the auto_scale attribute. It doesn’t have a default value so the server will decide what the value will be. This means that the attribute is NOT in my .tf file. I create the Resource, everything goes well, and I get a success response. When inspecting the state file, auto_scale has the following value:

"auto_scale": {
  "max": 2,
  "min": 2
}

Everything looks fine, but the next time I run terraform plan without changing anything in my .tf file, Terraform will detect changes. The weird thing is that the plan output only shows attributes that will be known after apply (they don’t use state for unknown). There is no attribute that explicitly shows its current value and the proposed new value. And get this, auto_scale doesn’t even show up in the output (it’s probably in the 6 unchanged attributes hidden section). If I apply the changes, nothing will be done, since my code only updates attributes it needs to (and, unlike what Terraform thinks, nothings needs an update), Terraform will report success, but when planning again the same issue will happen.

I know that auto_scale is the attribute causing the issue because of the following log message:

2024-02-16T11:16:48.833-0300 [DEBUG] provider.terraform-provider-<redacted>: Detected value change between proposed new state and prior state: tf_provider_addr=registry.terraform.io/<redacted> tf_req_id=09b172bb-c42d-259d-ddc5-cc5e6a032876 tf_rpc=PlanResourceChange tf_attribute_path=auto_scale tf_resource_type=<redacted> @caller=/Users/amadeusk525/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.3.4/internal/fwserver/server_planresourcechange.go:186 @module=sdk.framework timestamp=2024-02-16T11:16:48.829-0300

The weird thing is that some log message BEFORE that one, I have the following:

Value switched to prior value due to semantic equality logic: tf_attribute_path=auto_scale.max
Value switched to prior value due to semantic equality logic: tf_attribute_path=auto_scale.min
Value switched to prior value due to semantic equality logic: tf_attribute_path=auto_scale

This should mean that auto_scale was detected as unchanged, right? Why does it all of the sudden detect changes later on? And it doesn’t even show the changes in the output! I hope someone can share some light on this, as I’ve been having a hard time trying to fix the issue. The other Resource with this problem is being triggered by a StringAttribute, so I don’t think that the fact that auto_scale is an object matters. In that case, user_data (the string attribute) does show up in the plan output but only because it forces a replacement when changed, but it shows up like this:

+ user_data = (known after apply) # forces replacement

Hi @AmadeusK525 :wave:

Sorry you ran into trouble here.

It would be very helpful if you could supply a minimal reproducible example which includes:

  • Terraform configuration (i.e., what is in your .tf file during create, and subsequently).
  • The code for your provider resource schema.
  • The code for the CRUD functions in your provider resource.

This will help narrow down the potential causes, and possible resolutions to the issue that you describe.