SDKv2: Represent post value that is not returned by the API

Hi there,

I have an API that accepts an account object, where the account object is either identified using a “username” or a “uuid”. In recent events, the API no longer returns the “username”, but only the “uuid”. For backwards-compatibility of the Terraform plugin, I would like to incorporate this change, but by still allowing “usernames” as input (as the API still supports this).

The current issue is whenever the “username” is set in the Terraform plan, and I calculate the underlying “uuid” through the ReadContext, eventually the “username” that is defined in the Terraform file is always applied to the state. This causes issues when checking remote drifts as it always thinks there are changes.

I was hoping the ReadContext (with d.Set()) would apply to the eventual plan, but it seems the Terraform file is still leading in this.

Is there anyway, or are there any suggestion to create the described behaviour?

Just after posting this, I found a reference documentation of Magic Module (Google) on how to handle “permadiff” cases. The following link gives me an insight on how to handle such cases: Fix a permadiff | Magic Modules

In essence, I can just return the not included API value of the Terraform file. It is indeed expected the Terraform File to be leading.