forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source.go
54 lines (44 loc) · 963 Bytes
/
data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
}