/
resource_citrixadc_nstrafficdomain.go
102 lines (88 loc) · 2.62 KB
/
resource_citrixadc_nstrafficdomain.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package citrixadc
import (
"github.com/citrix/adc-nitro-go/resource/config/ns"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
"strconv"
)
func resourceCitrixAdcNstrafficdomain() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createNstrafficdomainFunc,
Read: readNstrafficdomainFunc,
Delete: deleteNstrafficdomainFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"td": {
Type: schema.TypeInt,
Required: true,
Computed: false,
ForceNew: true,
},
"aliasname": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"vmac": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}
func createNstrafficdomainFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createNstrafficdomainFunc")
client := meta.(*NetScalerNitroClient).client
td_Id := d.Get("td").(int)
nstrafficdomain := ns.Nstrafficdomain{
Aliasname: d.Get("aliasname").(string),
Td: d.Get("td").(int),
Vmac: d.Get("vmac").(string),
}
td_IdStr := strconv.Itoa(td_Id)
_, err := client.AddResource(service.Nstrafficdomain.Type(), td_IdStr, &nstrafficdomain)
if err != nil {
return err
}
d.SetId(td_IdStr)
err = readNstrafficdomainFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this nstrafficdomain but we can't read it ?? %s", td_IdStr)
return nil
}
return nil
}
func readNstrafficdomainFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readNstrafficdomainFunc")
client := meta.(*NetScalerNitroClient).client
td_IdStr := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading nstrafficdomain state %s", td_IdStr)
data, err := client.FindResource(service.Nstrafficdomain.Type(), td_IdStr)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing nstrafficdomain state %s", td_IdStr)
d.SetId("")
return nil
}
d.Set("aliasname", data["aliasname"])
d.Set("td", data["td"])
d.Set("vmac", data["vmac"])
return nil
}
func deleteNstrafficdomainFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteNstrafficdomainFunc")
client := meta.(*NetScalerNitroClient).client
nstrafficdomainName := d.Id()
err := client.DeleteResource(service.Nstrafficdomain.Type(), nstrafficdomainName)
if err != nil {
return err
}
d.SetId("")
return nil
}