What to store in state for optional attributes

I’m writing a provider using the Framework, and I think I’m misunderstanding something about what to store in state.

My resource has a tags attribute which is an optional set of strings. If the config leaves tags null, then Terraform should not change tags.

When I leave the attribute null in config, the API returns an empty array for the value of tags. When I save that empty array in state, I get the error:

When applying changes to meraki_network.n, provider
│ "provider[\"registry.terraform.io/jennings/meraki\"]" produced an unexpected new value: .tags: was   
│ null, but now cty.SetValEmpty(cty.String).

The error seems to be telling me I should be storing types.Set{Null: true} in state, not types.Set{Value: make([]types.String)}.


  1. When refreshing state in Read, the API returns the empty array, and I don’t have access to Config to know that it was left null, so I don’t know whether I should or should not set it to null. How do I avoid
  2. Why should I leave it null, anyway? I thought state was supposed to reflect exactly what the resource looks like in reality, and then Terraform decides from config which values it wants to change.

Thanks for any clarification you can give. I’m sure my mental model is flawed somehow.