-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource_instance.go
78 lines (72 loc) · 1.73 KB
/
resource_instance.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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/scalablespace/goss"
)
func resourceInstance() *schema.Resource {
return &schema.Resource{
Create: resourceCreate,
Read: resourceRead,
Update: func(data *schema.ResourceData, i interface{}) error {
return nil
},
Delete: resourceDelete,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the instance",
},
"plan": {
Type: schema.TypeString,
Required: true,
Description: "Name of the plan, valid options are: lemur, tiger, bunny, rabbit, panda, ape, hippo, lion",
},
"dc": {
Type: schema.TypeString,
Required: true,
Description: "Name of the region you want to create your instance in",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Sensitive: true,
Description: "API key for the CloudAMQP instance",
},
},
}
}
func resourceCreate(d *schema.ResourceData, meta interface{}) error {
api := meta.(*goss.API)
keys := []string{"name", "plan", "dc"}
params := make(map[string]interface{})
for _, k := range keys {
if v := d.Get(k); v != nil {
params[k] = v
}
}
data, err := api.CreateInstance(params)
if err != nil {
return err
}
d.SetId(data["id"].(string))
for k, v := range data {
d.Set(k, v)
}
return nil
}
func resourceRead(d *schema.ResourceData, meta interface{}) error {
api := meta.(*goss.API)
data, err := api.ReadInstance(d.Id())
if err != nil {
return err
}
for k, v := range data {
d.Set(k, v)
}
return nil
}
func resourceDelete(d *schema.ResourceData, meta interface{}) error {
api := meta.(*goss.API)
return api.DeleteInstance(d.Id())
}