forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_cobbler_kickstart_file.go
83 lines (63 loc) · 2.01 KB
/
resource_cobbler_kickstart_file.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
package cobbler
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
cobbler "github.com/jtopjian/cobblerclient"
)
func resourceKickstartFile() *schema.Resource {
return &schema.Resource{
Create: resourceKickstartFileCreate,
Read: resourceKickstartFileRead,
Update: resourceKickstartFileUpdate,
Delete: resourceKickstartFileDelete,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"body": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}
func resourceKickstartFileCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
ks := cobbler.KickstartFile{
Name: d.Get("name").(string),
Body: d.Get("body").(string),
}
log.Printf("[DEBUG] Cobbler KickstartFile: Create Options: %#v", ks)
if err := config.cobblerClient.CreateKickstartFile(ks); err != nil {
return fmt.Errorf("Cobbler KickstartFile: Error Creating: %s", err)
}
d.SetId(ks.Name)
return resourceKickstartFileRead(d, meta)
}
func resourceKickstartFileRead(d *schema.ResourceData, meta interface{}) error {
// Since all attributes are required and not computed,
// there's no reason to read.
return nil
}
func resourceKickstartFileUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
ks := cobbler.KickstartFile{
Name: d.Id(),
Body: d.Get("body").(string),
}
log.Printf("[DEBUG] Cobbler KickstartFile: Updating Kickstart (%s) with options: %+v", d.Id(), ks)
if err := config.cobblerClient.CreateKickstartFile(ks); err != nil {
return fmt.Errorf("Cobbler KickstartFile: Error Updating (%s): %s", d.Id(), err)
}
return resourceKickstartFileRead(d, meta)
}
func resourceKickstartFileDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
if err := config.cobblerClient.DeleteKickstartFile(d.Id()); err != nil {
return fmt.Errorf("Cobbler KickstartFile: Error Deleting (%s): %s", d.Id(), err)
}
return nil
}