import ( "github.com/hashicorp/terraform/helper/schema" ) func resourceMyResource() *schema.Resource { return &schema.Resource{ // ... Schema: map[string]*schema.Schema{ "my_property": { Type: schema.TypeString, Optional: true, }, }, } } func myFunction(d *schema.ResourceData, meta interface{}) error { myProperty, ok := d.GetOk("my_property") if !ok { // my_property was not set } // ... }
import ( "github.com/hashicorp/terraform/helper/schema" ) func resourceMyResource() *schema.Resource { return &schema.Resource{ // ... Schema: map[string]*schema.Schema{ "my_list": { Type: schema.TypeList, Elem: &schema.Schema{Type: schema.TypeInt}, Optional: true, }, }, } } func myFunction(d *schema.ResourceData, meta interface{}) error { myList, ok := d.GetOk("my_list") if !ok { // my_list was not set } else { for _, item := range myList.([]int) { // ... } } // ... }In this example, we define a schema with an optional list property called "my_list" containing integer values. In the `myFunction` function, we use `ResourceData.GetOk` to retrieve the value of "my_list" and iterate over its contents if it exists.