Terraform Import without ID

Hi team.
I am implementing a unique case of a resource that is actually a singleton, so it doesn’t have an ID field (for that matter, the Get command from the API side doesn’t accept any parameter func GetSingleton()*singleton). How should I implement ImportState in such a case?

Hey there @OrNovo :wave:,

While id is required by Terraform to execute an import, it’s not actually required to be stored in state, so for your situation I’d say that it doesn’t really matter what the value of ID is. In your ImportState method you can just ignore the ID passed in and perform the import without it.

import {
  to = examplecloud_thing.test_resource
  id = "singleton"
}

So just to make sure - I need to add an ID to the resource schema, and resource.ImportStatePassthroughID(ctx, path.Root("id"), request, response) as the ImportState implementation?

The id value in an import block refers to some identifier that the provider can use to locate the resource’s data. It does not necessarily correlate to an id attribute on your resource. You can completely ignore the import id if it’s not needed, as long as import state returns something with sufficient data that the provider can use to read the full resource, that could even mean all attributes are initially set to null if no information is actually needed.