/
resource_citrixadc_authenticationwebauthpolicy.go
129 lines (112 loc) · 4.31 KB
/
resource_citrixadc_authenticationwebauthpolicy.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/authentication"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"fmt"
"log"
)
func resourceCitrixAdcAuthenticationwebauthpolicy() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createAuthenticationwebauthpolicyFunc,
Read: readAuthenticationwebauthpolicyFunc,
Update: updateAuthenticationwebauthpolicyFunc,
Delete: deleteAuthenticationwebauthpolicyFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Computed: false,
ForceNew: true,
},
"action": {
Type: schema.TypeString,
Required: true,
Computed: false,
},
"rule": {
Type: schema.TypeString,
Required: true,
Computed: false,
},
},
}
}
func createAuthenticationwebauthpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createAuthenticationwebauthpolicyFunc")
client := meta.(*NetScalerNitroClient).client
authenticationwebauthpolicyName := d.Get("name").(string)
authenticationwebauthpolicy := authentication.Authenticationwebauthpolicy{
Action: d.Get("action").(string),
Name: d.Get("name").(string),
Rule: d.Get("rule").(string),
}
_, err := client.AddResource(service.Authenticationwebauthpolicy.Type(), authenticationwebauthpolicyName, &authenticationwebauthpolicy)
if err != nil {
return err
}
d.SetId(authenticationwebauthpolicyName)
err = readAuthenticationwebauthpolicyFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this authenticationwebauthpolicy but we can't read it ?? %s", authenticationwebauthpolicyName)
return nil
}
return nil
}
func readAuthenticationwebauthpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readAuthenticationwebauthpolicyFunc")
client := meta.(*NetScalerNitroClient).client
authenticationwebauthpolicyName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading authenticationwebauthpolicy state %s", authenticationwebauthpolicyName)
data, err := client.FindResource(service.Authenticationwebauthpolicy.Type(), authenticationwebauthpolicyName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing authenticationwebauthpolicy state %s", authenticationwebauthpolicyName)
d.SetId("")
return nil
}
d.Set("action", data["action"])
d.Set("name", data["name"])
d.Set("rule", data["rule"])
return nil
}
func updateAuthenticationwebauthpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In updateAuthenticationwebauthpolicyFunc")
client := meta.(*NetScalerNitroClient).client
authenticationwebauthpolicyName := d.Get("name").(string)
authenticationwebauthpolicy := authentication.Authenticationwebauthpolicy{
Name: d.Get("name").(string),
}
hasChange := false
if d.HasChange("action") {
log.Printf("[DEBUG] citrixadc-provider: Action has changed for authenticationwebauthpolicy %s, starting update", authenticationwebauthpolicyName)
authenticationwebauthpolicy.Action = d.Get("action").(string)
hasChange = true
}
if d.HasChange("rule") {
log.Printf("[DEBUG] citrixadc-provider: Rule has changed for authenticationwebauthpolicy %s, starting update", authenticationwebauthpolicyName)
authenticationwebauthpolicy.Rule = d.Get("rule").(string)
hasChange = true
}
if hasChange {
_, err := client.UpdateResource(service.Authenticationwebauthpolicy.Type(), authenticationwebauthpolicyName, &authenticationwebauthpolicy)
if err != nil {
return fmt.Errorf("Error updating authenticationwebauthpolicy %s", authenticationwebauthpolicyName)
}
}
return readAuthenticationwebauthpolicyFunc(d, meta)
}
func deleteAuthenticationwebauthpolicyFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteAuthenticationwebauthpolicyFunc")
client := meta.(*NetScalerNitroClient).client
authenticationwebauthpolicyName := d.Id()
err := client.DeleteResource(service.Authenticationwebauthpolicy.Type(), authenticationwebauthpolicyName)
if err != nil {
return err
}
d.SetId("")
return nil
}