func resourceMyResource() *schema.Resource { return &schema.Resource{ // omitted code for defining schema Read: func(d *schema.ResourceData, m interface{}) error { id := d.Id() // use id to fetch the corresponding resource from the provider // and populate d with its attributes return nil }, } }
func resourceNewResource() *schema.Resource { return &schema.Resource{ Create: func(d *schema.ResourceData, m interface{}) error { // create a new resource using d.Get() to retrieve attribute values // and set its Id as a string newId := "myNewResource-" + time.Now().Format("2006-01-02_15:04:05") d.SetId(newId) // save the new resource to the provider // so it can be read and updated in future runs return saveNewResourceToProvider(d) }, } }In summary, the "github.com.hashicorp.terraform.helper.schema" package is a library that provides utilities for working with Terraform resource schemas, including working with the ResourceData Id. The examples above demonstrate how to retrieve and set the Id of a resource instance in a provider.