-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_directory.go
71 lines (62 loc) · 1.54 KB
/
resource_directory.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
package main
import (
"os"
"strconv"
"github.com/hashicorp/terraform/helper/schema"
)
func resourceDirectoryCreate(d *schema.ResourceData, m interface{}) error {
name := d.Get(fsNAME).(string)
fileMode := os.FileMode(0777)
if mode1, ok := d.GetOk(fsMODE); ok {
if mode2, err := strconv.ParseInt(mode1.(string), 16, 64); err == nil {
fileMode = os.FileMode(mode2)
}
}
if err := os.Mkdir(name, fileMode); err != nil {
return err
}
d.SetId(name)
return nil
}
func resourceDirectoryRead(d *schema.ResourceData, m interface{}) error {
return nil
}
func resourceDirectoryUpdate(d *schema.ResourceData, m interface{}) error {
oldName1, newName1 := d.GetChange(fsNAME)
oldName := oldName1.(string)
newName := newName1.(string)
if oldName == "" {
return resourceDirectoryCreate(d, m)
}
err := os.Rename(oldName, newName)
return err
}
func resourceDirectoryDelete(d *schema.ResourceData, m interface{}) error {
name := d.Get(fsNAME).(string)
if err := os.Remove(name); err != nil {
return err
}
return nil
}
func resourceDirectorySchema() map[string]*schema.Schema {
result := map[string]*schema.Schema{
fsNAME: &schema.Schema{
Type: schema.TypeString,
Required: true,
},
fsMODE: &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
}
return result
}
func resourceDirectory() *schema.Resource {
return &schema.Resource{
Create: resourceDirectoryCreate,
Read: resourceDirectoryRead,
Update: resourceDirectoryUpdate,
Delete: resourceDirectoryDelete,
Schema: resourceDirectorySchema(),
}
}