github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/null/data_source.go (about) 1 package null 2 3 import ( 4 "fmt" 5 "math/rand" 6 "time" 7 8 "github.com/hashicorp/terraform/helper/schema" 9 ) 10 11 func init() { 12 rand.Seed(time.Now().Unix()) 13 } 14 15 func dataSource() *schema.Resource { 16 return &schema.Resource{ 17 Read: dataSourceRead, 18 19 Schema: map[string]*schema.Schema{ 20 "inputs": &schema.Schema{ 21 Type: schema.TypeMap, 22 Optional: true, 23 }, 24 "outputs": &schema.Schema{ 25 Type: schema.TypeMap, 26 Computed: true, 27 }, 28 "random": &schema.Schema{ 29 Type: schema.TypeString, 30 Computed: true, 31 }, 32 "has_computed_default": &schema.Schema{ 33 Type: schema.TypeString, 34 Optional: true, 35 Computed: true, 36 }, 37 }, 38 } 39 } 40 41 func dataSourceRead(d *schema.ResourceData, meta interface{}) error { 42 43 inputs := d.Get("inputs") 44 d.Set("outputs", inputs) 45 46 d.Set("random", fmt.Sprintf("%d", rand.Int())) 47 if d.Get("has_computed_default") == "" { 48 d.Set("has_computed_default", "default") 49 } 50 51 d.SetId("static") 52 53 return nil 54 }