-
Notifications
You must be signed in to change notification settings - Fork 26
/
resource_admin_email.go
68 lines (54 loc) · 1.67 KB
/
resource_admin_email.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
package aviatrix
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/AviatrixSystems/go-aviatrix/goaviatrix"
)
func resourceAdminEmail() *schema.Resource {
return &schema.Resource{
Create: resourceAdminEmailCreate,
Read: resourceAdminEmailRead,
Update: resourceAdminEmailUpdate,
Delete: resourceAdminEmailDelete,
Schema: map[string]*schema.Schema{
"admin_email": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
},
}
}
func resourceAdminEmailCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
adminEmail := d.Get("admin_email").(string)
log.Printf("[INFO] Creating Aviatrix Admin Email: %s", adminEmail)
err := client.SetAdminEmail(adminEmail)
if err != nil {
return fmt.Errorf("Failed to set Aviatrix Admin Email: %s", err)
}
d.SetId(adminEmail)
return nil
}
func resourceAdminEmailRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
log.Printf("[INFO] Getting Aviatrix Admin Email")
adminEmail, err := client.GetAdminEmail(client.Username, client.Password)
if err != nil {
return fmt.Errorf("Failed to get Aviatrix Admin Email: %s", err)
}
d.SetId(adminEmail)
return nil
}
func resourceAdminEmailUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceAdminEmailCreate(d, meta)
}
func resourceAdminEmailDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
log.Printf("[INFO] Deleting Aviatrix Admin Email")
err := client.SetAdminEmail("[email protected]")
if err != nil {
return fmt.Errorf("Failed to remove Aviatrix Admin Email: %s", err)
}
return nil
}