-
Notifications
You must be signed in to change notification settings - Fork 26
/
resource_customer_id.go
69 lines (56 loc) · 1.71 KB
/
resource_customer_id.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
package aviatrix
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/AviatrixSystems/go-aviatrix/goaviatrix"
)
func resourceCustomerID() *schema.Resource {
return &schema.Resource{
Create: resourceCustomerIDCreate,
Read: resourceCustomerIDRead,
Update: resourceCustomerIDUpdate,
Delete: resourceCustomerIDDelete,
Schema: map[string]*schema.Schema{
"customer_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
// TODO: add license list
},
}
}
func resourceCustomerIDCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
customerID := d.Get("customer_id").(string)
log.Printf("[INFO] Creating Aviatrix Customer ID: %s", customerID)
_, err := client.SetCustomerID(customerID)
if err != nil {
return fmt.Errorf("Failed to set Aviatrix Customer ID: %s", err)
}
d.SetId(customerID)
return nil
}
func resourceCustomerIDRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
log.Printf("[INFO] Getting Aviatrix Customer ID")
_, customerID, err := client.GetCustomerID()
if err != nil {
return fmt.Errorf("Failed to get Aviatrix Customer ID: %s", err)
}
d.SetId(customerID)
log.Printf("[DEBUG] Customer ID: %s", customerID)
return nil
}
func resourceCustomerIDUpdate(d *schema.ResourceData, meta interface{}) error {
return resourceCustomerIDCreate(d, meta)
}
func resourceCustomerIDDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*goaviatrix.Client)
log.Printf("[INFO] Deleting Aviatrix Customer ID")
_, err := client.SetCustomerID("")
if err != nil {
return fmt.Errorf("Failed to remove Aviatrix Customer ID: %s", err)
}
return nil
}