Detecting changes between real world remote object state and current saved terraform state

I am developing terraform provider and have a requirement to check if there are any changes between remote object state and current saved terraform state. HasChange SDK method report changes between tf config and prior saved state, but there is no way to compare the attribute values before tf refresh state with remote object.

Full Usecase

I have a resource in the provider which cannot be deleted. So, on delete or destroy resource I want to put back all the attributes which are currently managed via tf provider to some system defaults. Basically, whatever attributes with non-zero value in current tf state file reset those to system default values. If there are any changes made to attributes outside terraform managed ones keep those values remain same.

For Ex:

Resource foo has two attributes of type string and both optional.

Step 1: Apply below config -

Resource Foo {

  Attr 1 = <some non-zero value>

}

Step 2: Update Attr 2 manually to some value

Attr2 =

Step 3: Run terraform destroy

Now, in deleteResource(ctx context.Context, d *schema.ResourceData, m interface{}) method hook in provider code, I want to set Attr1 to system default but keep Attr2 to remain same manually changed value.

Issue I am facing is, if I check *schema.ResourceData then that’s returning value after refreshing state so attr2 is returning value that’s set manually. GetRawConfig is returning nothing and GetRawState returning refreshed state instead of prior saved state.