diff --git a/builtin/providers/null/data_source.go b/builtin/providers/null/data_source.go new file mode 100644 index 000000000..065029e7e --- /dev/null +++ b/builtin/providers/null/data_source.go @@ -0,0 +1,54 @@ +package null + +import ( + "fmt" + "math/rand" + "time" + + "github.com/hashicorp/terraform/helper/schema" +) + +func init() { + rand.Seed(time.Now().Unix()) +} + +func dataSource() *schema.Resource { + return &schema.Resource{ + Read: dataSourceRead, + + Schema: map[string]*schema.Schema{ + "inputs": &schema.Schema{ + Type: schema.TypeMap, + Optional: true, + }, + "outputs": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + }, + "random": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + "has_computed_default": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + }, + }, + } +} + +func dataSourceRead(d *schema.ResourceData, meta interface{}) error { + + inputs := d.Get("inputs") + d.Set("outputs", inputs) + + d.Set("random", fmt.Sprintf("%d", rand.Int())) + if d.Get("has_computed_default") == "" { + d.Set("has_computed_default", "default") + } + + d.SetId("static") + + return nil +} diff --git a/builtin/providers/null/provider.go b/builtin/providers/null/provider.go index 7e2a70c6c..7f67877fd 100644 --- a/builtin/providers/null/provider.go +++ b/builtin/providers/null/provider.go @@ -13,5 +13,9 @@ func Provider() terraform.ResourceProvider { ResourcesMap: map[string]*schema.Resource{ "null_resource": resource(), }, + + DataSourcesMap: map[string]*schema.Resource{ + "null_data_source": dataSource(), + }, } }