forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
77 lines (69 loc) · 1.8 KB
/
resource.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
71
72
73
74
75
76
77
package test
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func testResource() *schema.Resource {
return &schema.Resource{
Create: testResourceCreate,
Read: testResourceRead,
Update: testResourceUpdate,
Delete: testResourceDelete,
Schema: map[string]*schema.Schema{
"required": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"optional": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"optional_bool": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
},
"optional_force_new": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"optional_computed_map": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Computed: true,
},
"computed_read_only": &schema.Schema{
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
"computed_read_only_force_new": &schema.Schema{
Type: schema.TypeString,
Computed: true,
ForceNew: true,
},
},
}
}
func testResourceCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId("testId")
// Required must make it through to Create
if _, ok := d.GetOk("required"); !ok {
return fmt.Errorf("Missing attribute 'required', but it's required!")
}
return testResourceRead(d, meta)
}
func testResourceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("computed_read_only", "value_from_api")
d.Set("computed_read_only_force_new", "value_from_api")
if _, ok := d.GetOk("optional_computed_map"); !ok {
d.Set("optional_computed_map", map[string]string{})
}
return nil
}
func testResourceUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}
func testResourceDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}