Skip to content

Commit bcd8514

Browse files
author
jaime Bernabe
authored
feat(lb): switch from regional to zoned API (#826)
BREAKING CHANGE: you must switch to zone instead of region in all lb related resources and datasources
1 parent 30e2489 commit bcd8514

31 files changed

+4078
-1388
lines changed

docs/data-sources/lb_ip.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ data "scaleway_lb_ip" "my_ip" {
3030
- `lb_id` - (Optional) The IP ID.
3131
Only one of `ip_address` and `ip_id` should be specified.
3232

33-
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#zones) in which the LB IP exists.
33+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
3434

3535
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the LB IP is associated with.
3636

docs/resources/lb.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resource "scaleway_lb_ip" "ip" {
1919
2020
resource "scaleway_lb" "base" {
2121
ip_id = scaleway_lb_ip.ip.id
22-
region = "fr-par"
22+
zone = "fr-par-1"
2323
type = "LB-S"
2424
}
2525
```
@@ -40,8 +40,7 @@ The following arguments are supported:
4040

4141
- `tags` - (Optional) The tags associated with the load-balancers.
4242

43-
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#regions) in which the load-balancer should be created.
44-
43+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
4544

4645
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.
4746

@@ -63,7 +62,7 @@ For instance, if you had the following:
6362

6463
```hcl
6564
resource "scaleway_lb" "base" {
66-
region = "fr-par"
65+
zone = "fr-par-1"
6766
type = "LB-S"
6867
}
6968
```
@@ -76,7 +75,7 @@ resource "scaleway_lb_ip" "ip" {
7675
7776
resource "scaleway_lb" "base" {
7877
ip_id = scaleway_lb_ip.ip.id
79-
region = "fr-par"
78+
zone = "fr-par-1"
8079
type = "LB-S"
8180
}
8281
```
@@ -97,10 +96,10 @@ and look for `ip_id`.
9796

9897
## Import
9998

100-
Load-Balancer can be imported using the `{region}/{id}`, e.g.
99+
Load-Balancer can be imported using the `{zone}/{id}`, e.g.
101100

102101
```bash
103-
$ terraform import scaleway_lb.lb01 fr-par/11111111-1111-1111-1111-111111111111
102+
$ terraform import scaleway_lb.lb01 fr-par-1/11111111-1111-1111-1111-111111111111
104103
```
105104

106105
Be aware that you will also need to import the `scaleway_lb_ip` resource.

docs/resources/lb_backend.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ In addition to all arguments above, the following attributes are exported:
8888

8989
## Import
9090

91-
Load-Balancer backend can be imported using the `{region}/{id}`, e.g.
91+
Load-Balancer backend can be imported using the `{zone}/{id}`, e.g.
9292

9393
```bash
94-
$ terraform import scaleway_lb_backend.backend01 fr-par/11111111-1111-1111-1111-111111111111
94+
$ terraform import scaleway_lb_backend.backend01 fr-par-1/11111111-1111-1111-1111-111111111111
9595
```

docs/resources/lb_frontend.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ In addition to all arguments above, the following attributes are exported:
126126

127127
## Import
128128

129-
Load-Balancer frontend can be imported using the `{region}/{id}`, e.g.
129+
Load-Balancer frontend can be imported using the `{zone}/{id}`, e.g.
130130

131131
```bash
132-
$ terraform import scaleway_lb_frontend.frontend01 fr-par/11111111-1111-1111-1111-111111111111
132+
$ terraform import scaleway_lb_frontend.frontend01 fr-par-1/11111111-1111-1111-1111-111111111111
133133
```

docs/resources/lb_ip.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ In addition to all arguments above, the following attributes are exported:
3636

3737
## Import
3838

39-
IPs can be imported using the `{region}/{id}`, e.g.
39+
IPs can be imported using the `{zone}/{id}`, e.g.
4040

4141
```bash
42-
$ terraform import scaleway_lb_ip.ip01 fr-par/11111111-1111-1111-1111-111111111111
42+
$ terraform import scaleway_lb_ip.ip01 fr-par-1/11111111-1111-1111-1111-111111111111
4343
```

go.mod

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ require (
55
github.com/dnaeon/go-vcr v1.1.0
66
github.com/dustin/go-humanize v1.0.0
77
github.com/google/go-cmp v0.5.5
8-
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
8+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
99
github.com/hashicorp/go-retryablehttp v0.6.8
1010
github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0
1111
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.7.0.20210427131120-0f06a0676b46
1212
github.com/stretchr/testify v1.7.0
1313
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
14+
golang.org/x/mod v0.4.2 // indirect
15+
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 // indirect
16+
golang.org/x/tools v0.1.0 // indirect
1417
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
1518
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1619
)

go.sum

+10-3
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0B
300300
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
301301
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
302302
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
303+
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
303304
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
304305
github.com/zclconf/go-cty v1.2.1 h1:vGMsygfmeCl4Xb6OA5U5XVAaQZ69FvoG7X2jUtQujb8=
305306
github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
@@ -350,8 +351,9 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
350351
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
351352
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
352353
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
353-
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
354354
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
355+
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
356+
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
355357
golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
356358
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
357359
golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -379,6 +381,7 @@ golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/
379381
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
380382
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
381383
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
384+
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
382385
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
383386
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
384387
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -395,6 +398,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
395398
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
396399
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
397400
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
401+
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
398402
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
399403
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
400404
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -424,8 +428,10 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w
424428
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
425429
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
426430
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
427-
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
428431
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
432+
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
433+
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744 h1:yhBbb4IRs2HS9PPlAg6DMC6mUOKexJBNsLf4Z+6En1Q=
434+
golang.org/x/sys v0.0.0-20210511113859-b0526f3d8744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
429435
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
430436
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
431437
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -472,8 +478,9 @@ golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roY
472478
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
473479
golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
474480
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
475-
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed h1:+qzWo37K31KxduIYaBeMqJ8MUOyTayOQKpH9aDPLMSY=
476481
golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
482+
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
483+
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
477484
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
478485
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
479486
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

scaleway/data_source_lb_ip.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,25 @@ func dataSourceScalewayLbIP() *schema.Resource {
2929
}
3030

3131
return &schema.Resource{
32-
ReadContext: dataSourceScalewayLbIPRead,
33-
Schema: dsSchema,
32+
ReadContext: dataSourceScalewayLbIPRead,
33+
Schema: dsSchema,
34+
SchemaVersion: 1,
35+
StateUpgraders: []schema.StateUpgrader{
36+
{Version: 0, Type: lbUpgradeV1SchemaType(), Upgrade: lbUpgradeV1SchemaUpgradeFunc},
37+
},
3438
}
3539
}
3640

3741
func dataSourceScalewayLbIPRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
38-
api, region, err := lbAPIWithRegion(d, meta)
42+
api, zone, err := lbAPIWithZone(d, meta)
3943
if err != nil {
4044
return diag.FromErr(err)
4145
}
4246

4347
ipID, ok := d.GetOk("ip_id")
4448
if !ok { // Get IP by region and IP address.
45-
res, err := api.ListIPs(&lb.ListIPsRequest{
46-
Region: region,
49+
res, err := api.ListIPs(&lb.ZonedAPIListIPsRequest{
50+
Zone: zone,
4751
IPAddress: expandStringPtr(d.Get("ip_address")),
4852
ProjectID: expandStringPtr(d.Get("project_id")),
4953
}, scw.WithContext(ctx))
@@ -59,9 +63,9 @@ func dataSourceScalewayLbIPRead(ctx context.Context, d *schema.ResourceData, met
5963
ipID = res.IPs[0].ID
6064
}
6165

62-
regionalID := datasourceNewRegionalizedID(ipID, region)
63-
d.SetId(regionalID)
64-
err = d.Set("ip_id", regionalID)
66+
zoneID := datasourceNewZonedID(ipID, zone)
67+
d.SetId(zoneID)
68+
err = d.Set("ip_id", zoneID)
6569
if err != nil {
6670
return diag.FromErr(err)
6771
}

scaleway/helpers.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ func regionSchema() *schema.Schema {
288288
}
289289
}
290290

291+
// regionComputedSchema returns a standard schema for a zone
292+
func regionComputedSchema() *schema.Schema {
293+
return &schema.Schema{
294+
Type: schema.TypeString,
295+
Description: "The region of the resource",
296+
Computed: true,
297+
}
298+
}
299+
291300
// validateStringInSliceWithWarning helps to only returns warnings in case we got a non public locality passed
292301
func validateStringInSliceWithWarning(correctValues []string, field string) func(i interface{}, path cty.Path) diag.Diagnostics {
293302
return func(i interface{}, path cty.Path) diag.Diagnostics {
@@ -490,7 +499,7 @@ func diffSuppressFuncIgnoreCaseAndHyphen(k, old, new string, d *schema.ResourceD
490499
}
491500

492501
// diffSuppressFuncLocality is a SuppressDiffFunc to remove the locality from an ID when checking diff.
493-
// e.g. 2c1a1716-5570-4668-a50a-860c90beabf6 == fr-par/2c1a1716-5570-4668-a50a-860c90beabf6
502+
// e.g. 2c1a1716-5570-4668-a50a-860c90beabf6 == fr-par-1/2c1a1716-5570-4668-a50a-860c90beabf6
494503
func diffSuppressFuncLocality(k, old, new string, d *schema.ResourceData) bool {
495504
return expandID(old) == expandID(new)
496505
}

scaleway/helpers_lb.go

+50-16
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
package scaleway
22

33
import (
4+
"context"
5+
"fmt"
46
"strings"
57
"time"
68

9+
"github.com/hashicorp/go-cty/cty"
710
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
811
"github.com/scaleway/scaleway-sdk-go/api/lb/v1"
912
"github.com/scaleway/scaleway-sdk-go/scw"
13+
validator "github.com/scaleway/scaleway-sdk-go/validation"
1014
)
1115

1216
const (
1317
LbWaitForTimeout = 10 * time.Minute
1418
defaultLbLbTimeout = 10 * time.Minute
1519
)
1620

17-
// lbAPI returns a new lb API
18-
func lbAPI(m interface{}) *lb.API {
21+
// lbAPIWithZone returns an lb API WITH zone for a Create request
22+
func lbAPIWithZone(d *schema.ResourceData, m interface{}) (*lb.ZonedAPI, scw.Zone, error) {
1923
meta := m.(*Meta)
20-
return lb.NewAPI(meta.scwClient)
21-
}
22-
23-
// lbAPIWithRegion returns a new lb API and the region for a Create request
24-
func lbAPIWithRegion(d *schema.ResourceData, m interface{}) (*lb.API, scw.Region, error) {
25-
meta := m.(*Meta)
26-
lbAPI := lb.NewAPI(meta.scwClient)
24+
lbAPI := lb.NewZonedAPI(meta.scwClient)
2725

28-
region, err := extractRegion(d, meta)
26+
zone, err := extractZone(d, meta)
2927
if err != nil {
3028
return nil, "", err
3129
}
32-
return lbAPI, region, nil
30+
return lbAPI, zone, nil
3331
}
3432

35-
// lbAPIWithRegionAndID returns an lb API with region and ID extracted from the state
36-
func lbAPIWithRegionAndID(m interface{}, id string) (*lb.API, scw.Region, string, error) {
33+
// lbAPIWithZoneAndID returns an lb API with zone and ID extracted from the state
34+
func lbAPIWithZoneAndID(m interface{}, id string) (*lb.ZonedAPI, scw.Zone, string, error) {
3735
meta := m.(*Meta)
38-
lbAPI := lb.NewAPI(meta.scwClient)
36+
lbAPI := lb.NewZonedAPI(meta.scwClient)
3937

40-
region, ID, err := parseRegionalID(id)
38+
zone, ID, err := parseZonedID(id)
4139
if err != nil {
4240
return nil, "", "", err
4341
}
44-
return lbAPI, region, ID, nil
42+
return lbAPI, zone, ID, nil
4543
}
4644

4745
func flattenLbBackendMarkdownAction(action lb.OnMarkedDownAction) interface{} {
@@ -259,3 +257,39 @@ func expandLbProxyProtocol(raw interface{}) lb.ProxyProtocol {
259257
func flattenLbProxyProtocol(pp lb.ProxyProtocol) interface{} {
260258
return strings.TrimPrefix(pp.String(), "proxy_protocol_")
261259
}
260+
261+
func lbUpgradeV1SchemaType() cty.Type {
262+
return cty.Object(map[string]cty.Type{
263+
"id": cty.String,
264+
})
265+
}
266+
267+
// lbUpgradeV1UpgradeFunc allow upgrade the from regional to a zoned resource.
268+
func lbUpgradeV1SchemaUpgradeFunc(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
269+
var err error
270+
// element id: upgrade
271+
ID, exist := rawState["id"]
272+
if !exist {
273+
return nil, fmt.Errorf("upgrade: id not exist")
274+
}
275+
rawState["id"], err = lbUpgradeV1RegionalToZonedID(ID.(string))
276+
if err != nil {
277+
return nil, err
278+
}
279+
// return rawState updated
280+
return rawState, nil
281+
}
282+
283+
func lbUpgradeV1RegionalToZonedID(element string) (string, error) {
284+
locality, id, err := parseLocalizedID(element)
285+
// return error if can't parse
286+
if err != nil {
287+
return "", fmt.Errorf("upgrade: could not retrieve the locality from `%s`", element)
288+
}
289+
// if locality is already zoned return
290+
if validator.IsZone(locality) {
291+
return element, nil
292+
}
293+
// append zone 1 as default: e.g. fr-par-1
294+
return fmt.Sprintf("%s-1/%s", locality, id), nil
295+
}

0 commit comments

Comments
 (0)