import "github.com/hashicorp/terraform/helper/schema" func resourceElasticsearch() *schema.Resource { return &schema.Resource{ Create: resourceElasticsearchCreate, Read: resourceElasticsearchRead, Update: resourceElasticsearchUpdate, Delete: resourceElasticsearchDelete, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, Required: true, }, "region": { Type: schema.TypeString, Required: true, }, }, } } func resourceElasticsearchCreate(d *schema.ResourceData, meta interface{}) error { name := d.Get("name").(string) region := d.Get("region").(string) // Create Elasticsearch cluster with the given name and region d.SetId(name) return nil }
import "github.com/hashicorp/terraform/helper/schema" func resourceRedis() *schema.Resource { return &schema.Resource{ Create: resourceRedisCreate, Read: resourceRedisRead, Update: resourceRedisUpdate, Delete: resourceRedisDelete, Schema: map[string]*schema.Schema{ "name": { Type: schema.TypeString, Required: true, }, "size": { Type: schema.TypeInt, Required: true, }, }, } } func resourceRedisUpdate(d *schema.ResourceData, meta interface{}) error { name := d.Get("name").(string) size := d.Get("size").(int) // Update the size of the Redis instance with the given name d.Set("size", size) return nil }In this example, we define a Terraform resource that updates the size of a Redis instance. During the Update operation, we retrieve the values of the "name" and "size" properties from the ResourceData object, use them to update the Redis instance, and then set the new size value on the ResourceData object using Set.