-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
resource_defaults.go
70 lines (61 loc) · 1.51 KB
/
resource_defaults.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package test
import (
"fmt"
"math/rand"
"github.com/hashicorp/terraform/helper/schema"
)
func testResourceDefaults() *schema.Resource {
return &schema.Resource{
Create: testResourceDefaultsCreate,
Read: testResourceDefaultsRead,
Delete: testResourceDefaultsDelete,
Update: testResourceDefaultsUpdate,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"default_string": {
Type: schema.TypeString,
Optional: true,
Default: "default string",
},
"default_bool": {
Type: schema.TypeString,
Optional: true,
Default: true,
},
"nested": {
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"string": {
Type: schema.TypeString,
Optional: true,
Default: "default nested",
},
"optional": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
},
}
}
func testResourceDefaultsCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(fmt.Sprintf("%x", rand.Int63()))
return testResourceDefaultsRead(d, meta)
}
func testResourceDefaultsUpdate(d *schema.ResourceData, meta interface{}) error {
return testResourceDefaultsRead(d, meta)
}
func testResourceDefaultsRead(d *schema.ResourceData, meta interface{}) error {
return nil
}
func testResourceDefaultsDelete(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}