This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
/
model_sdwan_ipv4_prefix_list_policy_object.go
83 lines (75 loc) · 2.29 KB
/
model_sdwan_ipv4_prefix_list_policy_object.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
// Code generated by "gen/generator.go"; DO NOT EDIT.
package provider
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
type IPv4PrefixList struct {
Id types.String `tfsdk:"id"`
Version types.Int64 `tfsdk:"version"`
Name types.String `tfsdk:"name"`
Entries []IPv4PrefixListEntries `tfsdk:"entries"`
}
type IPv4PrefixListEntries struct {
Prefix types.String `tfsdk:"prefix"`
Le types.Int64 `tfsdk:"le"`
Ge types.Int64 `tfsdk:"ge"`
}
func (data IPv4PrefixList) getType() string {
return "prefix"
}
func (data IPv4PrefixList) toBody(ctx context.Context) string {
body, _ := sjson.Set("", "description", "Desc Not Required")
body, _ = sjson.Set(body, "name", data.Name.ValueString())
body, _ = sjson.Set(body, "type", "prefix")
if len(data.Entries) > 0 {
body, _ = sjson.Set(body, "entries", []interface{}{})
for _, item := range data.Entries {
itemBody := ""
if !item.Prefix.IsNull() {
itemBody, _ = sjson.Set(itemBody, "ipPrefix", item.Prefix.ValueString())
}
if !item.Le.IsNull() {
itemBody, _ = sjson.Set(itemBody, "le", fmt.Sprint(item.Le.ValueInt64()))
}
if !item.Ge.IsNull() {
itemBody, _ = sjson.Set(itemBody, "ge", fmt.Sprint(item.Ge.ValueInt64()))
}
body, _ = sjson.SetRaw(body, "entries.-1", itemBody)
}
}
return body
}
func (data *IPv4PrefixList) fromBody(ctx context.Context, res gjson.Result) {
if value := res.Get("name"); value.Exists() {
data.Name = types.StringValue(value.String())
} else {
data.Name = types.StringNull()
}
if value := res.Get("entries"); value.Exists() {
data.Entries = make([]IPv4PrefixListEntries, 0)
value.ForEach(func(k, v gjson.Result) bool {
item := IPv4PrefixListEntries{}
if cValue := v.Get("ipPrefix"); cValue.Exists() {
item.Prefix = types.StringValue(cValue.String())
} else {
item.Prefix = types.StringNull()
}
if cValue := v.Get("le"); cValue.Exists() {
item.Le = types.Int64Value(cValue.Int())
} else {
item.Le = types.Int64Null()
}
if cValue := v.Get("ge"); cValue.Exists() {
item.Ge = types.Int64Value(cValue.Int())
} else {
item.Ge = types.Int64Null()
}
data.Entries = append(data.Entries, item)
return true
})
}
}