API object without ID

Hello again,

We have the next object:

type AccessControl struct {
    BucketID        int          `json:"bucket_id,omitempty"`
    ServerType      string       `json:"server_type,omitempty"`
    TargetID        int          `json:"target_id,omitempty"`
    Type            string       `json:"type,omitempty"`
    TimingStrategy  string       `json:"timing_strategy,omitempty"`
    TargetName      string       `json:"target_name,omitempty"`
    Limits          *Limits      `json:"limits,omitempty"`

Could we made this resource from terraform without ID filed, or how I can resolve this issue?

Hi @skydion!

I’m assuming from your Go struct example here that you’re working on implementing a Terraform Provider, and your question is about what to pass to d.SetId for resource types that don’t have a natural id.

Earlier versions of Terraform considered “id” to be more special than Terraform 0.12 does, but in current provider code the only requirement is that it be set to something non-empty before the provider functions return in order to signal that the object is present. Conversely, calling d.SetId("") signals that the object no longer exists.

For resource types that don’t have any useful string to provide as an id, you can just use a short placeholder string. A common choice is "-", which is nice because it’s short and unobtrusive when it appears in the Terraform UI and hopefully doesn’t leave the user wondering what it means.

It’s likely that a future version of the Terraform SDK will not require an id value at all, because Terraform 0.12 doesn’t actually require it anymore, but the SDK continues to require it at the moment because providers are currently built to work with both Terraform 0.11 and 0.12, and thus we must work within the 0.11 constraints.

Hello, @apparentlymart

Thank you for explanation.