/
resource_citrixadc_icaaccessprofile.go
210 lines (194 loc) · 7.64 KB
/
resource_citrixadc_icaaccessprofile.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package citrixadc
import (
"github.com/citrix/adc-nitro-go/resource/config/ica"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"fmt"
"log"
)
func resourceCitrixAdcIcaaccessprofile() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createIcaaccessprofileFunc,
Read: readIcaaccessprofileFunc,
Update: updateIcaaccessprofileFunc,
Delete: deleteIcaaccessprofileFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"clientaudioredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"clientclipboardredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"clientcomportredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"clientdriveredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"clientprinterredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"clientusbdriveredirection": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"connectclientlptports": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"localremotedatasharing": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"multistream": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}
func createIcaaccessprofileFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createIcaaccessprofileFunc")
client := meta.(*NetScalerNitroClient).client
icaaccessprofileName := d.Get("name").(string)
icaaccessprofile := ica.Icaaccessprofile{
Clientaudioredirection: d.Get("clientaudioredirection").(string),
Clientclipboardredirection: d.Get("clientclipboardredirection").(string),
Clientcomportredirection: d.Get("clientcomportredirection").(string),
Clientdriveredirection: d.Get("clientdriveredirection").(string),
Clientprinterredirection: d.Get("clientprinterredirection").(string),
Clientusbdriveredirection: d.Get("clientusbdriveredirection").(string),
Connectclientlptports: d.Get("connectclientlptports").(string),
Localremotedatasharing: d.Get("localremotedatasharing").(string),
Multistream: d.Get("multistream").(string),
Name: d.Get("name").(string),
}
_, err := client.AddResource("icaaccessprofile", icaaccessprofileName, &icaaccessprofile)
if err != nil {
return err
}
d.SetId(icaaccessprofileName)
err = readIcaaccessprofileFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this icaaccessprofile but we can't read it ?? %s", icaaccessprofileName)
return nil
}
return nil
}
func readIcaaccessprofileFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readIcaaccessprofileFunc")
client := meta.(*NetScalerNitroClient).client
icaaccessprofileName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading icaaccessprofile state %s", icaaccessprofileName)
data, err := client.FindResource("icaaccessprofile", icaaccessprofileName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing icaaccessprofile state %s", icaaccessprofileName)
d.SetId("")
return nil
}
d.Set("name", data["name"])
d.Set("clientaudioredirection", data["clientaudioredirection"])
d.Set("clientclipboardredirection", data["clientclipboardredirection"])
d.Set("clientcomportredirection", data["clientcomportredirection"])
d.Set("clientdriveredirection", data["clientdriveredirection"])
d.Set("clientprinterredirection", data["clientprinterredirection"])
d.Set("clientusbdriveredirection", data["clientusbdriveredirection"])
d.Set("connectclientlptports", data["connectclientlptports"])
d.Set("localremotedatasharing", data["localremotedatasharing"])
d.Set("multistream", data["multistream"])
return nil
}
func updateIcaaccessprofileFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In updateIcaaccessprofileFunc")
client := meta.(*NetScalerNitroClient).client
icaaccessprofileName := d.Get("name").(string)
icaaccessprofile := ica.Icaaccessprofile{
Name: d.Get("name").(string),
}
hasChange := false
if d.HasChange("clientaudioredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientaudioredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientaudioredirection = d.Get("clientaudioredirection").(string)
hasChange = true
}
if d.HasChange("clientclipboardredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientclipboardredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientclipboardredirection = d.Get("clientclipboardredirection").(string)
hasChange = true
}
if d.HasChange("clientcomportredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientcomportredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientcomportredirection = d.Get("clientcomportredirection").(string)
hasChange = true
}
if d.HasChange("clientdriveredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientdriveredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientdriveredirection = d.Get("clientdriveredirection").(string)
hasChange = true
}
if d.HasChange("clientprinterredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientprinterredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientprinterredirection = d.Get("clientprinterredirection").(string)
hasChange = true
}
if d.HasChange("clientusbdriveredirection") {
log.Printf("[DEBUG] citrixadc-provider: Clientusbdriveredirection has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Clientusbdriveredirection = d.Get("clientusbdriveredirection").(string)
hasChange = true
}
if d.HasChange("connectclientlptports") {
log.Printf("[DEBUG] citrixadc-provider: Connectclientlptports has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Connectclientlptports = d.Get("connectclientlptports").(string)
hasChange = true
}
if d.HasChange("localremotedatasharing") {
log.Printf("[DEBUG] citrixadc-provider: Localremotedatasharing has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Localremotedatasharing = d.Get("localremotedatasharing").(string)
hasChange = true
}
if d.HasChange("multistream") {
log.Printf("[DEBUG] citrixadc-provider: Multistream has changed for icaaccessprofile %s, starting update", icaaccessprofileName)
icaaccessprofile.Multistream = d.Get("multistream").(string)
hasChange = true
}
if hasChange {
err := client.UpdateUnnamedResource("icaaccessprofile", &icaaccessprofile)
if err != nil {
return fmt.Errorf("Error updating icaaccessprofile %s", icaaccessprofileName)
}
}
return readIcaaccessprofileFunc(d, meta)
}
func deleteIcaaccessprofileFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteIcaaccessprofileFunc")
client := meta.(*NetScalerNitroClient).client
icaaccessprofileName := d.Id()
err := client.DeleteResource("icaaccessprofile", icaaccessprofileName)
if err != nil {
return err
}
d.SetId("")
return nil
}