/
resource_citrixadc_appfwxmlschema.go
105 lines (91 loc) · 2.73 KB
/
resource_citrixadc_appfwxmlschema.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
package citrixadc
import (
"github.com/citrix/adc-nitro-go/resource/config/appfw"
"github.com/citrix/adc-nitro-go/service"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"log"
)
func resourceCitrixAdcAppfwxmlschema() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
Create: createAppfwxmlschemaFunc,
Read: readAppfwxmlschemaFunc,
Delete: deleteAppfwxmlschemaFunc,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Computed: false,
ForceNew: true,
},
"src": {
Type: schema.TypeString,
Required: true,
Computed: false,
ForceNew: true,
},
"comment": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"overwrite": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}
func createAppfwxmlschemaFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In createAppfwxmlschemaFunc")
client := meta.(*NetScalerNitroClient).client
appfwxmlschemaName := d.Get("name").(string)
appfwxmlschema := appfw.Appfwxmlschema{
Comment: d.Get("comment").(string),
Name: d.Get("name").(string),
Overwrite: d.Get("overwrite").(bool),
Src: d.Get("src").(string),
}
err := client.ActOnResource(service.Appfwxmlschema.Type(), &appfwxmlschema, "Import")
if err != nil {
return err
}
d.SetId(appfwxmlschemaName)
err = readAppfwxmlschemaFunc(d, meta)
if err != nil {
log.Printf("[ERROR] netscaler-provider: ?? we just created this appfwxmlschema but we can't read it ?? %s", appfwxmlschemaName)
return nil
}
return nil
}
func readAppfwxmlschemaFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In readAppfwxmlschemaFunc")
client := meta.(*NetScalerNitroClient).client
appfwxmlschemaName := d.Id()
log.Printf("[DEBUG] citrixadc-provider: Reading appfwxmlschema state %s", appfwxmlschemaName)
data, err := client.FindResource(service.Appfwxmlschema.Type(), appfwxmlschemaName)
if err != nil {
log.Printf("[WARN] citrixadc-provider: Clearing appfwxmlschema state %s", appfwxmlschemaName)
d.SetId("")
return nil
}
d.Set("name", data["name"])
return nil
}
func deleteAppfwxmlschemaFunc(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] citrixadc-provider: In deleteAppfwxmlschemaFunc")
client := meta.(*NetScalerNitroClient).client
appfwxmlschemaName := d.Id()
err := client.DeleteResource(service.Appfwxmlschema.Type(), appfwxmlschemaName)
if err != nil {
return err
}
d.SetId("")
return nil
}