forked from aiven/terraform-provider-aiven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_project.go
87 lines (74 loc) · 1.83 KB
/
resource_project.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
package main
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/jelmersnoeck/aiven"
)
func resourceProject() *schema.Resource {
return &schema.Resource{
Create: resourceProjectCreate,
Read: resourceProjectRead,
Update: resourceProjectUpdate,
Delete: resourceProjectDelete,
Schema: map[string]*schema.Schema{
"card_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Credit card ID",
},
"cloud": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Target cloud",
},
"project": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Project name",
},
},
}
}
func resourceProjectCreate(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
project, err := client.Projects.Create(
aiven.CreateProjectRequest{
d.Get("card_id").(string),
d.Get("cloud").(string),
d.Get("project").(string),
},
)
if err != nil {
return err
}
d.SetId(project.Name + "!")
return nil
}
func resourceProjectRead(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
project, err := client.Projects.Get(d.Get("project").(string))
if err != nil {
return err
}
d.Set("project", project.Name)
return nil
}
func resourceProjectUpdate(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
project, err := client.Projects.Update(
d.Get("project").(string),
aiven.UpdateProjectRequest{
d.Get("card_id").(string),
d.Get("cloud").(string),
d.Get("project").(string),
},
)
if err != nil {
return err
}
d.SetId(project.Name + "!")
return nil
}
func resourceProjectDelete(d *schema.ResourceData, m interface{}) error {
client := m.(*aiven.Client)
return client.Projects.Delete(d.Get("project").(string))
}