github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/test/data_source.go (about)

     1  package test
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  func testDataSource() *schema.Resource {
    10  	return &schema.Resource{
    11  		Read: testDataSourceRead,
    12  
    13  		Schema: map[string]*schema.Schema{
    14  			"list": {
    15  				Type:     schema.TypeList,
    16  				Computed: true,
    17  				Elem:     &schema.Schema{Type: schema.TypeString},
    18  			},
    19  
    20  			"input": {
    21  				Type:     schema.TypeString,
    22  				Optional: true,
    23  			},
    24  
    25  			"output": {
    26  				Type:     schema.TypeString,
    27  				Computed: true,
    28  			},
    29  		},
    30  	}
    31  }
    32  
    33  func testDataSourceRead(d *schema.ResourceData, meta interface{}) error {
    34  	d.SetId(time.Now().UTC().String())
    35  	d.Set("list", []interface{}{"one", "two", "three"})
    36  
    37  	if input, hasInput := d.GetOk("input"); hasInput {
    38  		d.Set("output", input)
    39  	} else {
    40  		d.Set("output", "some output")
    41  	}
    42  
    43  	return nil
    44  }