/
resource_router_bgp_address_family_ipv4_flowspec_neighbor_ipv6_neighbor.go
135 lines (127 loc) · 5.76 KB
/
resource_router_bgp_address_family_ipv4_flowspec_neighbor_ipv6_neighbor.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
package thunder
import (
"context"
edpt "github.com/a10networks/terraform-provider-thunder/thunder/axapi/endpoint"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor() *schema.Resource {
return &schema.Resource{
Description: "`thunder_router_bgp_address_family_ipv4_flowspec_neighbor_ipv6_neighbor`: Specify a peer-group neighbor router\n\n__PLACEHOLDER__",
CreateContext: resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborCreate,
UpdateContext: resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborUpdate,
ReadContext: resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborRead,
DeleteContext: resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborDelete,
Schema: map[string]*schema.Schema{
"activate": {
Type: schema.TypeInt, Optional: true, Default: 0, Description: "Enable the Address Family for this Neighbor",
},
"neighbor_ipv6": {
Type: schema.TypeString, Required: true, Description: "Neighbor IPv6 address",
},
"neighbor_route_map_lists": {
Type: schema.TypeList, Optional: true, Description: "",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nbr_route_map": {
Type: schema.TypeString, Optional: true, Description: "Apply route map to neighbor (Name of route map)",
},
"nbr_rmap_direction": {
Type: schema.TypeString, Optional: true, Description: "'in': in; 'out': out;",
},
},
},
},
"send_community_val": {
Type: schema.TypeString, Optional: true, Default: "both", Description: "'all': Send Standard, Extended, and Large Community attributes; 'both': Send Standard and Extended Community attributes; 'none': Disable Sending Community attributes; 'standard': Send Standard Community attributes; 'extended': Send Extended Community attributes; 'large': Send Large Community attributes;",
},
"uuid": {
Type: schema.TypeString, Optional: true, Computed: true, Description: "uuid of the object",
},
"as_number": {
Type: schema.TypeString, Required: true, Description: "AsNumber",
},
},
}
}
func resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborCreate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor(d)
d.SetId(obj.GetId())
err := obj.Post(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborRead(ctx, d, meta)
}
return diags
}
func resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborUpdate()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor(d)
err := obj.Put(client.Token, client.Host, logger)
if err != nil {
return diag.FromErr(err)
}
return resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborRead(ctx, d, meta)
}
return diags
}
func resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborDelete()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor(d)
err := obj.Delete(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(Thunder)
logger := client.log
logger.Println("resourceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborRead()")
var diags diag.Diagnostics
if client.Host != "" {
obj := dataToEndpointRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor(d)
err := obj.Get(client.Token, client.Host, d.Id(), logger)
if err != nil {
return diag.FromErr(err)
}
}
return diags
}
func getSliceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborNeighborRouteMapLists(d []interface{}) []edpt.RouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborNeighborRouteMapLists {
count1 := len(d)
ret := make([]edpt.RouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborNeighborRouteMapLists, 0, count1)
for _, item := range d {
in := item.(map[string]interface{})
var oi edpt.RouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborNeighborRouteMapLists
oi.NbrRouteMap = in["nbr_route_map"].(string)
oi.NbrRmapDirection = in["nbr_rmap_direction"].(string)
ret = append(ret, oi)
}
return ret
}
func dataToEndpointRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor(d *schema.ResourceData) edpt.RouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor {
var ret edpt.RouterBgpAddressFamilyIpv4FlowspecNeighborIpv6Neighbor
ret.Inst.Activate = d.Get("activate").(int)
ret.Inst.NeighborIpv6 = d.Get("neighbor_ipv6").(string)
ret.Inst.NeighborRouteMapLists = getSliceRouterBgpAddressFamilyIpv4FlowspecNeighborIpv6NeighborNeighborRouteMapLists(d.Get("neighbor_route_map_lists").([]interface{}))
ret.Inst.SendCommunityVal = d.Get("send_community_val").(string)
//omit uuid
ret.Inst.AsNumber = d.Get("as_number").(string)
return ret
}