forked from fortinetdev/terraform-provider-fortios
/
data_source_system_autoscript.go
186 lines (153 loc) · 4.85 KB
/
data_source_system_autoscript.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
// Copyright 2020 Fortinet, Inc. All rights reserved.
// Author: Frank Shen (@frankshen01), Hongbin Lu (@fgtdev-hblu)
// Documentation:
// Frank Shen (@frankshen01), Hongbin Lu (@fgtdev-hblu),
// Xing Li (@lix-fortinet), Yue Wang (@yuew-ftnt), Yuffie Zhu (@yuffiezhu)
// Description: Configure auto script.
package fortios
import (
"fmt"
"log"
"strconv"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
func dataSourceSystemAutoScript() *schema.Resource {
return &schema.Resource{
Read: dataSourceSystemAutoScriptRead,
Schema: map[string]*schema.Schema{
"vdomparam": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"repeat": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"start": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"script": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"output_size": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"timeout": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
},
}
}
func dataSourceSystemAutoScriptRead(d *schema.ResourceData, m interface{}) error {
c := m.(*FortiClient).Client
c.Retries = 1
vdomparam := ""
if v, ok := d.GetOk("vdomparam"); ok {
if s, ok := v.(string); ok {
vdomparam = s
}
}
mkey := ""
t := d.Get("name")
if v, ok := t.(string); ok {
mkey = v
} else if v, ok := t.(int); ok {
mkey = strconv.Itoa(v)
} else {
return fmt.Errorf("Error describing SystemAutoScript: type error")
}
o, err := c.ReadSystemAutoScript(mkey, vdomparam)
if err != nil {
return fmt.Errorf("Error describing SystemAutoScript: %v", err)
}
if o == nil {
d.SetId("")
return nil
}
err = dataSourceRefreshObjectSystemAutoScript(d, o)
if err != nil {
return fmt.Errorf("Error describing SystemAutoScript from API: %v", err)
}
d.SetId(mkey)
return nil
}
func dataSourceFlattenSystemAutoScriptName(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptInterval(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptRepeat(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptStart(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptScript(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptOutputSize(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceFlattenSystemAutoScriptTimeout(v interface{}, d *schema.ResourceData, pre string) interface{} {
return v
}
func dataSourceRefreshObjectSystemAutoScript(d *schema.ResourceData, o map[string]interface{}) error {
var err error
if err = d.Set("name", dataSourceFlattenSystemAutoScriptName(o["name"], d, "name")); err != nil {
if !fortiAPIPatch(o["name"]) {
return fmt.Errorf("Error reading name: %v", err)
}
}
if err = d.Set("interval", dataSourceFlattenSystemAutoScriptInterval(o["interval"], d, "interval")); err != nil {
if !fortiAPIPatch(o["interval"]) {
return fmt.Errorf("Error reading interval: %v", err)
}
}
if err = d.Set("repeat", dataSourceFlattenSystemAutoScriptRepeat(o["repeat"], d, "repeat")); err != nil {
if !fortiAPIPatch(o["repeat"]) {
return fmt.Errorf("Error reading repeat: %v", err)
}
}
if err = d.Set("start", dataSourceFlattenSystemAutoScriptStart(o["start"], d, "start")); err != nil {
if !fortiAPIPatch(o["start"]) {
return fmt.Errorf("Error reading start: %v", err)
}
}
if err = d.Set("script", dataSourceFlattenSystemAutoScriptScript(o["script"], d, "script")); err != nil {
if !fortiAPIPatch(o["script"]) {
return fmt.Errorf("Error reading script: %v", err)
}
}
if err = d.Set("output_size", dataSourceFlattenSystemAutoScriptOutputSize(o["output-size"], d, "output_size")); err != nil {
if !fortiAPIPatch(o["output-size"]) {
return fmt.Errorf("Error reading output_size: %v", err)
}
}
if err = d.Set("timeout", dataSourceFlattenSystemAutoScriptTimeout(o["timeout"], d, "timeout")); err != nil {
if !fortiAPIPatch(o["timeout"]) {
return fmt.Errorf("Error reading timeout: %v", err)
}
}
return nil
}
func dataSourceFlattenSystemAutoScriptFortiTestDebug(d *schema.ResourceData, fosdebugsn int, fosdebugbeg int, fosdebugend int) {
log.Printf(strconv.Itoa(fosdebugsn))
e := validation.IntBetween(fosdebugbeg, fosdebugend)
log.Printf("ER List: %v, %v", strings.Split("FortiOS Ver", " "), e)
}