/
resource_citrixadc_systemglobal_authenticationldappolicy_binding.go
174 lines (150 loc) · 5.23 KB
/
resource_citrixadc_systemglobal_authenticationldappolicy_binding.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
package citrixadc
import (
"github.com/citrix/adc-nitro-go/resource/config/system"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"fmt"
"log"
)
func resourceCitrixAdcSystemglobal_authenticationldappolicy_binding() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createSystemglobal_authenticationldappolicy_bindingFunc,
Read: readSystemglobal_authenticationldappolicy_bindingFunc,
Delete: deleteSystemglobal_authenticationldappolicy_bindingFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"policyname": {
Type: schema.TypeString,
Required: true,
Computed: false,
ForceNew: true,
},
"builtin": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Computed: true,
ForceNew: true,
},
"feature": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"globalbindtype": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"gotopriorityexpression": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"nextfactor": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"priority": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}
func createSystemglobal_authenticationldappolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createSystemglobal_authenticationldappolicy_bindingFunc")
client := meta.(*NetScalerNitroClient).client
policyname := d.Get("policyname").(string)
systemglobal_authenticationldappolicy_binding := system.Systemglobalauthenticationldappolicybinding{
Builtin: toStringList(d.Get("builtin").([]interface{})),
Feature: d.Get("feature").(string),
Globalbindtype: d.Get("globalbindtype").(string),
Gotopriorityexpression: d.Get("gotopriorityexpression").(string),
Nextfactor: d.Get("nextfactor").(string),
Policyname: d.Get("policyname").(string),
Priority: d.Get("priority").(int),
}
err := client.UpdateUnnamedResource(service.Systemglobal_authenticationldappolicy_binding.Type(), &systemglobal_authenticationldappolicy_binding)
if err != nil {
return err
}
d.SetId(policyname)
err = readSystemglobal_authenticationldappolicy_bindingFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this systemglobal_authenticationldappolicy_binding but we can't read it ?? %s", policyname)
return nil
}
return nil
}
func readSystemglobal_authenticationldappolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readSystemglobal_authenticationldappolicy_bindingFunc")
client := meta.(*NetScalerNitroClient).client
policyname := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading systemglobal_authenticationldappolicy_binding state %s", policyname)
findParams := service.FindParams{
ResourceType: "systemglobal_authenticationldappolicy_binding",
ResourceMissingErrorCode: 258,
}
dataArr, err := client.FindResourceArrayWithParams(findParams)
// Unexpected error
if err != nil {
log.Printf("[DEBUG] citrixadc-provider: Error during FindResourceArrayWithParams %s", err.Error())
return err
}
// Resource is missing
if len(dataArr) == 0 {
log.Printf("[DEBUG] citrixadc-provider: FindResourceArrayWithParams returned empty array")
log.Printf("[WARN] citrixadc-provider: Clearing systemglobal_authenticationldappolicy_binding state %s", policyname)
d.SetId("")
return nil
}
// Iterate through results to find the one with the right id
foundIndex := -1
for i, v := range dataArr {
if v["policyname"].(string) == policyname {
foundIndex = i
break
}
}
// Resource is missing
if foundIndex == -1 {
log.Printf("[DEBUG] citrixadc-provider: FindResourceArrayWithParams secondIdComponent not found in array")
log.Printf("[WARN] citrixadc-provider: Clearing systemglobal_authenticationldappolicy_binding state %s", policyname)
d.SetId("")
return nil
}
// Fallthrough
data := dataArr[foundIndex]
d.Set("builtin", data["builtin"])
d.Set("feature", data["feature"])
// d.Set("globalbindtype", data["globalbindtype"])
d.Set("gotopriorityexpression", data["gotopriorityexpression"])
d.Set("nextfactor", data["nextfactor"])
d.Set("policyname", data["policyname"])
d.Set("priority", data["priority"])
return nil
}
func deleteSystemglobal_authenticationldappolicy_bindingFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteSystemglobal_authenticationldappolicy_bindingFunc")
client := meta.(*NetScalerNitroClient).client
policyname := d.Id()
args := make([]string, 0)
args = append(args, fmt.Sprintf("policyname:%s", policyname))
err := client.DeleteResourceWithArgs(service.Systemglobal_authenticationldappolicy_binding.Type(), "", args)
if err != nil {
return err
}
d.SetId("")
return nil
}