forked from aiven/terraform-provider-aiven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_database.go
82 lines (72 loc) · 2.03 KB
/
resource_database.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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/jelmersnoeck/aiven"
)
func resourceDatabase() *schema.Resource {
return &schema.Resource{
Create: resourceDatabaseCreate,
Read: resourceDatabaseRead,
Update: resourceDatabaseUpdate,
Delete: resourceDatabaseDelete,
// TODO: add user config
Schema: map[string]*schema.Schema{
"project": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Project to link the database to",
},
"service_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Service to link the database to",
},
"database": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Service database name",
},
"lc_collate": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Default string sort order (LC_COLLATE) of the database. Default value: en_US.UTF-8",
},
"lc_ctype": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Default character classification (LC_CTYPE) of the database. Default value: en_US.UTF-8",
},
},
}
}
func resourceDatabaseCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
database, err := client.Databases.Create(
d.Get("project").(string),
d.Get("service_name").(string),
aiven.CreateDatabaseRequest{
d.Get("database").(string),
optionalString(d, "lc_collate"),
optionalString(d, "lc_type"),
},
)
if err != nil {
return err
}
d.SetId(database.Database + "!")
return nil
}
func resourceDatabaseRead(d *schema.ResourceData, m interface{}) error {
return nil
}
func resourceDatabaseUpdate(d *schema.ResourceData, m interface{}) error {
return nil
}
func resourceDatabaseDelete(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
return client.Databases.Delete(
d.Get("project").(string),
d.Get("service_name").(string),
d.Get("database").(string),
)
}