Terraform framework migration tests with non empty plan due to optional attributes

We’re facing an issue with our migration test where running the plan command results in a non-empty plan. This is observed when using the framework implemented provider to generate the plan, while the resource and Terraform state is created from the sdk v2 provider.
Here’s a snippet of the differences:

~ resource "mongodbatlas_alert_configuration" "test" {
	    id                     = "...."
	    # (4 unchanged attributes hidden)
	
	  ~ notification {
	      - sms_enabled   = false -> null
	        # (5 unchanged attributes hidden)
	    }
	  ~ notification {
	      - delay_min     = 0 -> null
	      - email_enabled = false -> null
	        # (3 unchanged attributes hidden)
	    }
	    # (2 unchanged blocks hidden)
	}

The attributes sms_enabled, email_enabled, and delay_min are optional and non-computed. They are not defined in the terraform configuration being tested, and we can see that the sdk v2 implementation defines default values in the terraform state.

Within the read operation of the framework implementation, these attributes are shown as known values with their respective default values in the state provided.

Is there a method to discern within the read operation that these attributes aren’t set in the configuration, allowing us to assign them null values? If not, what alternative solutions can prevent this non-empty plan?

Hi @AgustinBettati,
If I understand your situation correctly, then your existing resource using SDKv2 has the attributes sms_enabled , email_enabled , and delay_min showing up in Terraform state as non-nil when unconfigured but these attributes are being set as null values in the Framework resulting in an update operation.

The most straightforward way to fix this would be to add default values to the sms_enabled , email_enabled , and delay_min attributes in the Framework provider schema to keep it in parity with the SDKv2 provider behavior.

Hello @SBGoods, thanks for the quick response.

your existing resource using SDKv2 has the attributes sms_enabled , email_enabled , and delay_min showing up in Terraform state as non-nil when unconfigured but these attributes are being set as null values in the Framework resulting in an update operation.

In reality, the framework implemented provider is returning these attributes with the default values, which is why terraform generates an update plan to remove these fields (as they are not defined in the configuration). If they are defined as null, there’s no plan output. I’m having difficulty ensuring these values are properly set to null, especially since the state in the read request already comes with these values defined.

Based on what you’ve shared, a workaround I’ve considered is defining these attributes as both optional and computed. This would allow me to set their default values and Terraform wouldn’t generate any update plan. Does that sound reasonable to you?

Hi @AgustinBettati,

That plan sounds reasonable to me. If defining default values doesn’t fix the issue, then we might need more context on how specifically the schema and the Update() methods are implemented in the SDKv2 and Framework versions of the provider.