Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 4fa8c47

Browse files
shelomentsevdalexk53
authored andcommitted
GCLOUD2-5745: Actualized interfaces field in data source and resource for routes endpoint
1 parent d0a851a commit 4fa8c47

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

docs/data-sources/gcore_router.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ Read-Only:
8282

8383
Read-Only:
8484

85+
- `ip_address` (String)
86+
- `mac_address` (String)
87+
- `network_id` (String)
88+
- `port_id` (String)
8589
- `subnet_id` (String)
8690
- `type` (String)
8791

docs/resources/gcore_router.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ Required:
106106
- `subnet_id` (String) Subnet for router interface must have a gateway IP
107107
- `type` (String) must be 'subnet'
108108

109+
Read-Only:
110+
111+
- `ip_address` (String)
112+
- `mac_address` (String)
113+
- `network_id` (String)
114+
- `port_id` (String)
115+
109116

110117
<a id="nestedblock--routes"></a>
111118
### Nested Schema for `routes`

gcore/data_source_gcore_router.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,26 @@ func dataSourceRouter() *schema.Resource {
9090
Computed: true,
9191
Elem: &schema.Resource{
9292
Schema: map[string]*schema.Schema{
93+
"port_id": {
94+
Type: schema.TypeString,
95+
Computed: true,
96+
},
97+
"network_id": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
},
101+
"mac_address": {
102+
Type: schema.TypeString,
103+
Computed: true,
104+
},
93105
"type": {
94106
Type: schema.TypeString,
95107
Computed: true,
96108
},
109+
"ip_address": {
110+
Type: schema.TypeString,
111+
Computed: true,
112+
},
97113
"subnet_id": {
98114
Type: schema.TypeString,
99115
Computed: true,
@@ -176,12 +192,18 @@ func dataSourceRouterRead(ctx context.Context, d *schema.ResourceData, m interfa
176192
d.Set("external_gateway_info", egilst)
177193
}
178194

179-
ifs := make([]map[string]string, len(router.Interfaces))
180-
for i, iface := range router.Interfaces {
181-
smap := make(map[string]string, 2)
182-
smap["type"] = "subnet"
183-
smap["subnet_id"] = iface.IPAssignments[0].SubnetID
184-
ifs[i] = smap
195+
ifs := make([]map[string]interface{}, 0, len(router.Interfaces))
196+
for _, iface := range router.Interfaces {
197+
for _, subnet := range iface.IPAssignments {
198+
smap := make(map[string]interface{}, 6)
199+
smap["port_id"] = iface.PortID
200+
smap["network_id"] = iface.NetworkID
201+
smap["mac_address"] = iface.MacAddress.String()
202+
smap["type"] = "subnet"
203+
smap["subnet_id"] = subnet.SubnetID
204+
smap["ip_address"] = subnet.IPAddress.String()
205+
ifs = append(ifs, smap)
206+
}
185207
}
186208
d.Set("interfaces", ifs)
187209

gcore/resource_gcore_router.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ func resourceRouter() *schema.Resource {
136136
Description: "Subnet for router interface must have a gateway IP",
137137
Required: true,
138138
},
139+
"port_id": {
140+
Type: schema.TypeString,
141+
Computed: true,
142+
},
143+
"network_id": {
144+
Type: schema.TypeString,
145+
Computed: true,
146+
},
147+
"mac_address": {
148+
Type: schema.TypeString,
149+
Computed: true,
150+
},
151+
"ip_address": {
152+
Type: schema.TypeString,
153+
Computed: true,
154+
},
139155
},
140156
},
141157
},
@@ -287,12 +303,18 @@ func resourceRouterRead(ctx context.Context, d *schema.ResourceData, m interface
287303
d.Set("external_gateway_info", egilst)
288304
}
289305

290-
ifs := make([]interface{}, len(router.Interfaces))
291-
for i, iface := range router.Interfaces {
292-
smap := make(map[string]interface{}, 2)
293-
smap["type"] = "subnet"
294-
smap["subnet_id"] = iface.IPAssignments[0].SubnetID
295-
ifs[i] = smap
306+
ifs := make([]interface{}, 0, len(router.Interfaces))
307+
for _, iface := range router.Interfaces {
308+
for _, subnet := range iface.IPAssignments {
309+
smap := make(map[string]interface{}, 6)
310+
smap["port_id"] = iface.PortID
311+
smap["network_id"] = iface.NetworkID
312+
smap["mac_address"] = iface.MacAddress.String()
313+
smap["type"] = "subnet"
314+
smap["subnet_id"] = subnet.SubnetID
315+
smap["ip_address"] = subnet.IPAddress.String()
316+
ifs = append(ifs, smap)
317+
}
296318
}
297319
if err := d.Set("interfaces", schema.NewSet(routerInterfaceUniqueID, ifs)); err != nil {
298320
return diag.FromErr(err)

0 commit comments

Comments
 (0)