forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_ignition_filesystem.go
113 lines (101 loc) · 2.62 KB
/
resource_ignition_filesystem.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package ignition
import (
"github.com/coreos/ignition/config/types"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceFilesystem() *schema.Resource {
return &schema.Resource{
Create: resourceFilesystemCreate,
Delete: resourceFilesystemDelete,
Exists: resourceFilesystemExists,
Read: resourceFilesystemRead,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"mount": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"device": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"format": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"force": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
"options": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"path": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
},
}
}
func resourceFilesystemCreate(d *schema.ResourceData, meta interface{}) error {
id, err := buildFilesystem(d, meta.(*cache))
if err != nil {
return err
}
d.SetId(id)
return nil
}
func resourceFilesystemDelete(d *schema.ResourceData, meta interface{}) error {
d.SetId("")
return nil
}
func resourceFilesystemExists(d *schema.ResourceData, meta interface{}) (bool, error) {
id, err := buildFilesystem(d, meta.(*cache))
if err != nil {
return false, err
}
return id == d.Id(), nil
}
func resourceFilesystemRead(d *schema.ResourceData, meta interface{}) error {
return nil
}
func buildFilesystem(d *schema.ResourceData, c *cache) (string, error) {
var mount *types.FilesystemMount
if _, ok := d.GetOk("mount"); ok {
mount = &types.FilesystemMount{
Device: types.Path(d.Get("mount.0.device").(string)),
Format: types.FilesystemFormat(d.Get("mount.0.format").(string)),
}
force, hasForce := d.GetOk("mount.0.force")
options, hasOptions := d.GetOk("mount.0.options")
if hasOptions || hasForce {
mount.Create = &types.FilesystemCreate{
Force: force.(bool),
Options: castSliceInterface(options.([]interface{})),
}
}
}
path := types.Path(d.Get("path").(string))
return c.addFilesystem(&types.Filesystem{
Name: d.Get("name").(string),
Mount: mount,
Path: &path,
}), nil
}