8
8
"time"
9
9
10
10
gcorecloud "github.com/G-Core/gcorelabscloud-go"
11
+ "github.com/G-Core/gcorelabscloud-go/gcore/port/v1/ports"
11
12
"github.com/G-Core/gcorelabscloud-go/gcore/reservedfixedip/v1/reservedfixedips"
12
13
"github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks"
13
14
"github.com/hashicorp/go-cty/cty"
@@ -17,6 +18,7 @@ import (
17
18
18
19
const (
19
20
reservedFixedIPsPoint = "reserved_fixed_ips"
21
+ portsPoint = "ports"
20
22
ReservedFixedIPCreateTimeout = 1200
21
23
)
22
24
@@ -135,17 +137,17 @@ func resourceReservedFixedIP() *schema.Resource {
135
137
},
136
138
"allowed_address_pairs" : {
137
139
Type : schema .TypeList ,
138
- Computed : true ,
140
+ Optional : true ,
139
141
Description : "Group of IP addresses that share the current IP as VIP" ,
140
142
Elem : & schema.Resource {
141
143
Schema : map [string ]* schema.Schema {
142
144
"ip_address" : {
143
145
Type : schema .TypeString ,
144
- Computed : true ,
146
+ Optional : true ,
145
147
},
146
148
"mac_address" : {
147
149
Type : schema .TypeString ,
148
- Computed : true ,
150
+ Optional : true ,
149
151
},
150
152
},
151
153
},
@@ -295,15 +297,37 @@ func resourceReservedFixedIPUpdate(ctx context.Context, d *schema.ResourceData,
295
297
return diag .FromErr (err )
296
298
}
297
299
300
+ id := d .Id ()
298
301
if d .HasChange ("is_vip" ) {
299
- id := d .Id ()
300
302
opts := reservedfixedips.SwitchVIPOpts {IsVip : d .Get ("is_vip" ).(bool )}
301
303
_ , err := reservedfixedips .SwitchVIP (client , id , opts ).Extract ()
302
304
if err != nil {
303
305
return diag .FromErr (err )
304
306
}
305
307
}
306
308
309
+ if d .HasChange ("allowed_address_pairs" ) {
310
+ aap := d .Get ("allowed_address_pairs" ).([]interface {})
311
+ allowedAddressPairs := make ([]reservedfixedips.AllowedAddressPairs , len (aap ))
312
+ for i , p := range aap {
313
+ pair := p .(map [string ]interface {})
314
+ allowedAddressPairs [i ] = reservedfixedips.AllowedAddressPairs {
315
+ IPAddress : pair ["ip_address" ].(string ),
316
+ MacAddress : pair ["mac_address" ].(string ),
317
+ }
318
+ }
319
+
320
+ clientPort , err := CreateClient (provider , d , portsPoint , versionPointV1 )
321
+ if err != nil {
322
+ return diag .FromErr (err )
323
+ }
324
+
325
+ opts := ports.AllowAddressPairsOpts {AllowedAddressPairs : allowedAddressPairs }
326
+ if _ , err := ports .AllowAddressPairs (clientPort , id , opts ).Extract (); err != nil {
327
+ return diag .FromErr (err )
328
+ }
329
+ }
330
+
307
331
d .Set ("last_updated" , time .Now ().Format (time .RFC850 ))
308
332
log .Println ("[DEBUG] Finish ReservedFixedIP updating" )
309
333
return resourceReservedFixedIPRead (ctx , d , m )
0 commit comments