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

Commit e80ffb2

Browse files
[Partner] Alexander Sokolovalexk53
authored andcommitted
allowed_address_pairs management added
1 parent b1cd919 commit e80ffb2

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

gcore/resource_gcore_reservedfixedip.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
gcorecloud "github.com/G-Core/gcorelabscloud-go"
11+
"github.com/G-Core/gcorelabscloud-go/gcore/port/v1/ports"
1112
"github.com/G-Core/gcorelabscloud-go/gcore/reservedfixedip/v1/reservedfixedips"
1213
"github.com/G-Core/gcorelabscloud-go/gcore/task/v1/tasks"
1314
"github.com/hashicorp/go-cty/cty"
@@ -17,6 +18,7 @@ import (
1718

1819
const (
1920
reservedFixedIPsPoint = "reserved_fixed_ips"
21+
portsPoint = "ports"
2022
ReservedFixedIPCreateTimeout = 1200
2123
)
2224

@@ -135,17 +137,17 @@ func resourceReservedFixedIP() *schema.Resource {
135137
},
136138
"allowed_address_pairs": {
137139
Type: schema.TypeList,
138-
Computed: true,
140+
Optional: true,
139141
Description: "Group of IP addresses that share the current IP as VIP",
140142
Elem: &schema.Resource{
141143
Schema: map[string]*schema.Schema{
142144
"ip_address": {
143145
Type: schema.TypeString,
144-
Computed: true,
146+
Optional: true,
145147
},
146148
"mac_address": {
147149
Type: schema.TypeString,
148-
Computed: true,
150+
Optional: true,
149151
},
150152
},
151153
},
@@ -295,15 +297,37 @@ func resourceReservedFixedIPUpdate(ctx context.Context, d *schema.ResourceData,
295297
return diag.FromErr(err)
296298
}
297299

300+
id := d.Id()
298301
if d.HasChange("is_vip") {
299-
id := d.Id()
300302
opts := reservedfixedips.SwitchVIPOpts{IsVip: d.Get("is_vip").(bool)}
301303
_, err := reservedfixedips.SwitchVIP(client, id, opts).Extract()
302304
if err != nil {
303305
return diag.FromErr(err)
304306
}
305307
}
306308

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+
307331
d.Set("last_updated", time.Now().Format(time.RFC850))
308332
log.Println("[DEBUG] Finish ReservedFixedIP updating")
309333
return resourceReservedFixedIPRead(ctx, d, m)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/G-Core/gcore-dns-sdk-go v0.2.3
88
github.com/G-Core/gcore-storage-sdk-go v0.1.3
99
github.com/G-Core/gcorelabscdn-go v0.1.20
10-
github.com/G-Core/gcorelabscloud-go v0.4.51
10+
github.com/G-Core/gcorelabscloud-go v0.4.54
1111
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
1212
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
1313
github.com/mitchellh/mapstructure v1.4.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ github.com/G-Core/gcore-storage-sdk-go v0.1.3 h1:vzgt5pKB3jsxbUs7jdEX1jyRC2YqbwL
8585
github.com/G-Core/gcore-storage-sdk-go v0.1.3/go.mod h1:e/5w5R2Uh6T7g6oAc5SpTKZJInFG6FyYYvGpUgRwCQ4=
8686
github.com/G-Core/gcorelabscdn-go v0.1.20 h1:RT/k4olBTPuVyE2LUlu5D9GTvj3hPA9NnBZwXYHFZxc=
8787
github.com/G-Core/gcorelabscdn-go v0.1.20/go.mod h1:iSGXaTvZBzDHQW+rKFS918BgFVpONcyLEijwh8WsXpE=
88-
github.com/G-Core/gcorelabscloud-go v0.4.51 h1:D47GHttvpeK2EFC2N9EnmyZmad/KwUyniowK2vyLHDQ=
89-
github.com/G-Core/gcorelabscloud-go v0.4.51/go.mod h1:nuDFy76Eja1EXBrG+q+dqpC2KqrHfID3JS8833LDJG8=
88+
github.com/G-Core/gcorelabscloud-go v0.4.54 h1:KDMRSGj/StmvFyqdIFng5Eb4eZB5W5GgIHZzrysh8VY=
89+
github.com/G-Core/gcorelabscloud-go v0.4.54/go.mod h1:nuDFy76Eja1EXBrG+q+dqpC2KqrHfID3JS8833LDJG8=
9090
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
9191
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
9292
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=

0 commit comments

Comments
 (0)