schema.ResourceImporter and ReadContext

I’m currently going through interesting exercise of generating HCL code for all of resources that our provider supports, so that adoption could be driven quicker - https://github.com/databrickslabs/terraform-provider-databricks/pull/415 - I know that code generation might become part of terraform 0.14, 0.15 or 0.19, but I’m not willing to wait that long :slight_smile:

During this exercise i’m finding out from time to time, that terraform import resource.name id is not always actually importing the full state, but rather just id property and that’s it.

So the question is: should schema.ResourceImporter#StateContext be calling ReadContext of the resource or not? I was observing contradictory behaviour, when i started experimenting with it. Plan to return more to it soon. But seeking insights from Terraform maintainers first.

/cc @paddy

I believe it depends on the provider. Technically, a provider just has to return some state for some number of resources from that request, so in theory some providers may be setting only their IDs in state and relying on refresh to call Read and populate the rest of it. I think with more concrete examples I may be able to point out why they’re behaving differently.

What should a provider do? IMHO, it’s probably best to pull in the latest state of a resource when importing and set the entire state in the response, but I don’t know that I have a strong opinion that that’s what has to be done, because a refresh will always happen before the state is used, I think? Unless you’re doing some remote state data source shenanigans, I suppose.