/
resource_citrixadc_lsnappsattributes.go
129 lines (112 loc) · 3.75 KB
/
resource_citrixadc_lsnappsattributes.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package citrixadc
import (
"github.com/citrix/adc-nitro-go/resource/config/lsn"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"fmt"
"log"
)
func resourceCitrixAdcLsnappsattributes() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createLsnappsattributesFunc,
Read: readLsnappsattributesFunc,
Update: updateLsnappsattributesFunc,
Delete: deleteLsnappsattributesFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"port": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"sessiontimeout": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"transportprotocol": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}
func createLsnappsattributesFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createLsnappsattributesFunc")
client := meta.(*NetScalerNitroClient).client
lsnappsattributesName := d.Get("name").(string)
lsnappsattributes := lsn.Lsnappsattributes{
Name: d.Get("name").(string),
Port: d.Get("port").(string),
Sessiontimeout: d.Get("sessiontimeout").(int),
Transportprotocol: d.Get("transportprotocol").(string),
}
_, err := client.AddResource("lsnappsattributes", lsnappsattributesName, &lsnappsattributes)
if err != nil {
return err
}
d.SetId(lsnappsattributesName)
err = readLsnappsattributesFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this lsnappsattributes but we can't read it ?? %s", lsnappsattributesName)
return nil
}
return nil
}
func readLsnappsattributesFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readLsnappsattributesFunc")
client := meta.(*NetScalerNitroClient).client
lsnappsattributesName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading lsnappsattributes state %s", lsnappsattributesName)
data, err := client.FindResource("lsnappsattributes", lsnappsattributesName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing lsnappsattributes state %s", lsnappsattributesName)
d.SetId("")
return nil
}
d.Set("name", data["name"])
d.Set("port", data["port"])
d.Set("sessiontimeout", data["sessiontimeout"])
d.Set("transportprotocol", data["transportprotocol"])
return nil
}
func updateLsnappsattributesFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In updateLsnappsattributesFunc")
client := meta.(*NetScalerNitroClient).client
lsnappsattributesName := d.Get("name").(string)
lsnappsattributes := lsn.Lsnappsattributes{
Name: d.Get("name").(string),
}
hasChange := false
if d.HasChange("sessiontimeout") {
log.Printf("[DEBUG] citrixadc-provider: Sessiontimeout has changed for lsnappsattributes %s, starting update", lsnappsattributesName)
lsnappsattributes.Sessiontimeout = d.Get("sessiontimeout").(int)
hasChange = true
}
if hasChange {
err := client.UpdateUnnamedResource("lsnappsattributes", &lsnappsattributes)
if err != nil {
return fmt.Errorf("Error updating lsnappsattributes %s", lsnappsattributesName)
}
}
return readLsnappsattributesFunc(d, meta)
}
func deleteLsnappsattributesFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteLsnappsattributesFunc")
client := meta.(*NetScalerNitroClient).client
lsnappsattributesName := d.Id()
err := client.DeleteResource("lsnappsattributes", lsnappsattributesName)
if err != nil {
return err
}
d.SetId("")
return nil
}