Skip to content

Commit fc88aaa

Browse files
TuetuopayabarbareAntoine Barbarejeansebastienhjerousseau
committed
Add support for LB Private Networks and LB Routes (scaleway#867)
* feat(lb): Add LB Private Network support * feat(lb): Add LB Route support * fixup! feat(lb): Add LB Private Network support * fix: increase rdb instance creation timeout to 15m (scaleway#868) Co-authored-by: Antoine Barbare <[email protected]> * doc: fix broken links following the release of the LB Zoned API (scaleway#871) * fix(docs) wrong name for resource iot_device (scaleway#869) Replace "scaleway_iot_hub_device" with "scaleway_iot_device" Co-authored-by: Rémy Léone <[email protected]> * chore: add a SECURITY.md (scaleway#872) * feat(domain): add record resource (scaleway#854) Co-authored-by: Jeremy JACQUEMIN <[email protected]> * doc: fix default runtime on k8s_pool (scaleway#873) * feat(iot): Add ability to set user device certificate (scaleway#859) * feat(iot): add ability to set user device certificate * test(iot): add test for user device certificate * test(iot): use unique resource names in tests to prevent conflict between tests set * test(iot): update cassettes for iot-device-minimal * chore: add a SECURITY.md (scaleway#872) * feat(domain): add record resource (scaleway#854) Co-authored-by: Jeremy JACQUEMIN <[email protected]> * doc: fix default runtime on k8s_pool (scaleway#873) Co-authored-by: Jerome Malinge <[email protected]> Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: jerjako <[email protected]> Co-authored-by: Jeremy JACQUEMIN <[email protected]> Co-authored-by: Jérémy THERIN <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> * feat(instance): Adding the datasource for instance ip (scaleway#870) * feat(instance): Adding the datasource for instance ip * refactoring: using ParseIP to validate the IP * fix: use proper validation * minor fixes * style(tfproviderlint): S019: schema should omit Computed, Optional, or Required set to false * fix: avoiding one api call if the ID is passed Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> * feat(lb): add data source for lb (scaleway#760) * feat(lb): add data source for lb * Fix * Update scaleway/data_source_lb.go Co-authored-by: Jerome Quere <[email protected]> * Update scaleway/data_source_lb.go Co-authored-by: Jerome Quere <[email protected]> * Update docs/data-sources/lb.md Co-authored-by: Quentin Brosse <[email protected]> * Fix * Fix * Fix * feat(lb): remove repeated explanation * feat(lb): update lb datasource reader with zone * feat(lb): update lb datasource reader with zone and test Co-authored-by: Jerome Quere <[email protected]> Co-authored-by: Quentin Brosse <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> Co-authored-by: Jaime BERNABE <[email protected]> * feat(vpcgw): add support for DHCP (scaleway#865) * feat(vpcgw): add support for DHCP * Fix * Fix * Fix * Fix * feat(lb): update vpc gw dhcp and small corrections * feat(vpc_public_gateway_dhcp): fix doc and test Co-authored-by: jaime Bernabe <[email protected]> Co-authored-by: Jaime BERNABE <[email protected]> * feat(domain): Add domain record data source (scaleway#874) * feat(domain): Add domain record data source * fix tests Co-authored-by: Jeremy JACQUEMIN <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> * chore: add support for dependabot (scaleway#877) * chore(deps): bump github.com/aws/aws-sdk-go from 1.39.3 to 1.40.53 (scaleway#878) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.39.3 to 1.40.53. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.39.3...v1.40.53) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump github.com/hashicorp/terraform-plugin-sdk/v2 (scaleway#880) Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.7.0 to 2.8.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md) - [Commits](hashicorp/terraform-plugin-sdk@v2.7.0...v2.8.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rémy Léone <[email protected]> * chore(deps): bump github.com/dnaeon/go-vcr from 1.1.0 to 1.2.0 (scaleway#879) Bumps [github.com/dnaeon/go-vcr](https://github.com/dnaeon/go-vcr) from 1.1.0 to 1.2.0. - [Release notes](https://github.com/dnaeon/go-vcr/releases) - [Commits](dnaeon/go-vcr@v1.1.0...v1.2.0) --- updated-dependencies: - dependency-name: github.com/dnaeon/go-vcr dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Rémy Léone <[email protected]> * chore(deps): bump github.com/aws/aws-sdk-go from 1.40.53 to 1.40.54 (scaleway#881) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.40.53 to 1.40.54. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.40.53...v1.40.54) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(provider): add profile name from configuration file support (scaleway#875) * feat(provider): add profile name from configuration file support * feat(provider): enhance error handling * chore(provider): add section about new profile feature usage * fix(provider): fix condition * Apply suggestions from code review Co-authored-by: jaime Bernabe <[email protected]> * feat(lb): test for private network * fix(lb): linter correction * fix(lb): lint correction * fix(lb): lint correction * chore(deps): bump github.com/aws/aws-sdk-go from 1.40.54 to 1.40.55 (scaleway#883) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.40.54 to 1.40.55. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.40.54...v1.40.55) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore: bump go version (scaleway#882) * k8s: add type on cluster (scaleway#886) * fix(vpc): reverse issue (scaleway#887) * fix(vpc): reverse issue * fix(vpc): add test to check reverse and address * fix(vpc): double retry interval Co-authored-by: scaleway-bot <[email protected]> * chore(deps): bump github.com/aws/aws-sdk-go from 1.40.55 to 1.40.56 (scaleway#888) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.40.55 to 1.40.56. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.40.55...v1.40.56) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jaime Bernabe <[email protected]> * fix(instance): security group rule read from api and acl database not statefull (scaleway#892) * Convert acl_rules from list to set * Fix read security group rules, removed from api * fix update typeSet for acl_rules * change order Co-authored-by: Rémy Léone <[email protected]> * chore(deps): bump github.com/aws/aws-sdk-go from 1.40.56 to 1.40.59 (scaleway#893) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.40.56 to 1.40.59. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.40.56...v1.40.59) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: jaime Bernabe <[email protected]> * feat(vpcgw): add gateway network resource (scaleway#891) Co-authored-by: scaleway-bot <[email protected]> * chore(deps): bump github.com/aws/aws-sdk-go from 1.40.59 to 1.41.0 (scaleway#894) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.40.59 to 1.41.0. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/main/CHANGELOG.md) - [Commits](aws/aws-sdk-go@v1.40.59...v1.41.0) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(lb): add wait lb in every resource * fix(lb): add test steps * feat(lb): add test and change schema * feat(lb): add test for dhcp * feat(lb): add cassette * feat(lb): add cassette basic and dhcp. add doc. add test dhcp * fix(lb_pn): lint * Remove trailing spaces * fix(lb_certificate): remove wait on lb_certificate * feat(lb): add release_ip to data_source * fix(lbacl): fix test lb acl * fix(lb-acl): update cassettes lb acl * fix(lb-pn): fix cassette * fix(lb-route): cassette Co-authored-by: abarbare <[email protected]> Co-authored-by: Antoine Barbare <[email protected]> Co-authored-by: Jean-Sébastien Hedde <[email protected]> Co-authored-by: jerousseau <[email protected]> Co-authored-by: Rémy Léone <[email protected]> Co-authored-by: jerjako <[email protected]> Co-authored-by: Jeremy JACQUEMIN <[email protected]> Co-authored-by: Jérémy THERIN <[email protected]> Co-authored-by: grom-42 <[email protected]> Co-authored-by: Jerome Malinge <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> Co-authored-by: Jerome Quere <[email protected]> Co-authored-by: Quentin Brosse <[email protected]> Co-authored-by: Jaime BERNABE <[email protected]> Co-authored-by: jaime Bernabe <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alexandre Bouthinon <[email protected]> Co-authored-by: scaleway-bot <[email protected]> Co-authored-by: LucasBoisserie <[email protected]>
1 parent 3e8f7a4 commit fc88aaa

22 files changed

+5704
-456
lines changed

docs/resources/lb.md

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resource "scaleway_lb" "base" {
2121
ip_id = scaleway_lb_ip.ip.id
2222
zone = "fr-par-1"
2323
type = "LB-S"
24+
release_ip = true
2425
}
2526
```
2627

@@ -40,6 +41,8 @@ The following arguments are supported:
4041

4142
- `tags` - (Optional) The tags associated with the load-balancers.
4243

44+
- `release_ip` - (Defaults to false) The release_ip allow release the ip address associated with the load-balancers.
45+
4346
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
4447

4548
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.
@@ -77,6 +80,7 @@ resource "scaleway_lb" "base" {
7780
ip_id = scaleway_lb_ip.ip.id
7881
zone = "fr-par-1"
7982
type = "LB-S"
83+
release_ip = true
8084
}
8185
```
8286

docs/resources/lb_private_network.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
page_title: "Scaleway: scaleway_lb_private_network"
3+
description: |-
4+
Manages Scaleway Load-Balancers private networks
5+
---
6+
7+
# scaleway_lb_private_network
8+
9+
Creates and manages Scaleway attach/detach private networks to Load-Balancers.
10+
For more information, see [the documentation](https://developers.scaleway.com/en/products/lb/zoned_api/#post-d4b30).
11+
12+
## Examples
13+
14+
### Basic
15+
16+
```hcl
17+
resource scaleway_vpc_private_network pn01 {
18+
name = "test-lb-pn"
19+
}
20+
21+
resource scaleway_lb_ip ip01 {}
22+
23+
resource scaleway_lb lb01 {
24+
ip_id = scaleway_lb_ip.ip01.id
25+
name = "test-lb"
26+
type = "lb-s"
27+
release_ip = true
28+
}
29+
30+
resource scaleway_lb_private_network lb01pn01 {
31+
lb_id = scaleway_lb.lb01.id
32+
private_network_id = scaleway_vpc_private_network.pn01.id
33+
static_config = ["172.16.0.100", "172.16.0.101"]
34+
}
35+
```
36+
37+
## Arguments Reference
38+
39+
The following arguments are supported:
40+
41+
- `lb_id` - (Required) The ID of the load-balancer to associate.
42+
43+
- `private_network_id` - (Required) The ID of the Private Network to associate.
44+
45+
- `static_config` - (Required) Define two local ip address of your choice for each load balancer instance. See below.
46+
47+
- `dhcp_config` - (Required) Set to true if you want to let DHCP assign IP addresses. See below.
48+
49+
~> **Important:** Only one of static_config and dhcp_config may be set.
50+
51+
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
52+
53+
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the load-balancer is associated with.
54+
55+
## Attributes Reference
56+
57+
In addition to all arguments above, the following attributes are exported:
58+
59+
- `status` - The Private Network attachment status
60+
61+
## Import
62+
63+
Load-Balancer private network can be imported using the `{zone}/{id}`, e.g.
64+
65+
```bash
66+
$ terraform import scaleway_lb_private_network.lb01pn01 fr-par/11111111-1111-1111-1111-111111111111
67+
```
68+
69+
The attachments can either be found in the console

scaleway/data_source_lb.go

+16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ func dataSourceScalewayLb() *schema.Resource {
2525
ValidateFunc: validationUUIDorUUIDWithLocality(),
2626
ConflictsWith: []string{"name"},
2727
}
28+
dsSchema["release_ip"] = &schema.Schema{
29+
Type: schema.TypeBool,
30+
Optional: true,
31+
Default: false,
32+
Description: "Release the IPs related to this load-balancer",
33+
}
2834

2935
return &schema.Resource{
3036
ReadContext: dataSourceScalewayLbRead,
@@ -57,6 +63,16 @@ func dataSourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta
5763
lbID = res.LBs[0].ID
5864
}
5965

66+
var relaseIPValue bool
67+
releaseIPAddress, releaseIPExist := d.GetOk("release_ip")
68+
if releaseIPExist {
69+
relaseIPValue = *expandBoolPtr(releaseIPAddress)
70+
}
71+
72+
err = d.Set("release_ip", relaseIPValue)
73+
if err != nil {
74+
return diag.FromErr(err)
75+
}
6076
zonedID := datasourceNewZonedID(lbID, zone)
6177
d.SetId(zonedID)
6278
err = d.Set("lb_id", zonedID)

scaleway/helpers_lb.go

+24
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,27 @@ func lbUpgradeV1RegionalToZonedID(element string) (string, error) {
293293
// append zone 1 as default: e.g. fr-par-1
294294
return fmt.Sprintf("%s-1/%s", locality, id), nil
295295
}
296+
297+
func expandLbPrivateNetworkStaticConfig(raw interface{}) *lb.PrivateNetworkStaticConfig {
298+
if raw == nil || len(raw.([]interface{})) < 1 {
299+
return nil
300+
}
301+
return &lb.PrivateNetworkStaticConfig{
302+
IPAddress: expandStrings(raw),
303+
}
304+
}
305+
306+
func flattenLbPrivateNetworkStaticConfig(cfg *lb.PrivateNetworkStaticConfig) []string {
307+
if cfg == nil {
308+
return nil
309+
}
310+
311+
return cfg.IPAddress
312+
}
313+
314+
func expandLbPrivateNetworkDHCPConfig(raw interface{}) *lb.PrivateNetworkDHCPConfig {
315+
if raw == nil || !raw.(bool) {
316+
return nil
317+
}
318+
return &lb.PrivateNetworkDHCPConfig{}
319+
}

scaleway/provider.go

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
8484
"scaleway_lb_backend": resourceScalewayLbBackend(),
8585
"scaleway_lb_certificate": resourceScalewayLbCertificate(),
8686
"scaleway_lb_frontend": resourceScalewayLbFrontend(),
87+
"scaleway_lb_private_network": resourceScalewayLbPrivateNetwork(),
88+
"scaleway_lb_route": resourceScalewayLbRoute(),
8789
"scaleway_registry_namespace": resourceScalewayRegistryNamespace(),
8890
"scaleway_rdb_acl": resourceScalewayRdbACL(),
8991
"scaleway_rdb_database": resourceScalewayRdbDatabase(),

scaleway/provider_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type TestTools struct {
8484
}
8585

8686
func NewTestTools(t *testing.T) *TestTools {
87-
// Create an http client with recording capabilities
87+
// Create a http client with recording capabilities
8888
httpClient, cleanup, err := getHTTPRecoder(t, *UpdateCassettes)
8989
require.NoError(t, err)
9090

scaleway/resource_lb.go

+45-10
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package scaleway
33
import (
44
"context"
55
"strings"
6+
"time"
67

78
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
910
"github.com/scaleway/scaleway-sdk-go/api/lb/v1"
1011
"github.com/scaleway/scaleway-sdk-go/scw"
1112
)
1213

14+
const (
15+
DefaultWaitLBRetryInterval = 30 * time.Second
16+
)
17+
1318
func resourceScalewayLb() *schema.Resource {
1419
return &schema.Resource{
1520
CreateContext: resourceScalewayLbCreate,
@@ -60,6 +65,12 @@ func resourceScalewayLb() *schema.Resource {
6065
Computed: true,
6166
Description: "The load-balance public IP address",
6267
},
68+
"release_ip": {
69+
Type: schema.TypeBool,
70+
Optional: true,
71+
Default: false,
72+
Description: "Release the IPs related to this load-balancer",
73+
},
6374
"region": regionComputedSchema(),
6475
"zone": zoneSchema(),
6576
"organization_id": organizationIDSchema(),
@@ -132,13 +143,20 @@ func resourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta in
132143
return diag.FromErr(err)
133144
}
134145

146+
var relaseIPValue bool
147+
releaseIPAddress, releaseIPPExist := d.GetOk("release_ip")
148+
if releaseIPPExist {
149+
relaseIPValue = *expandBoolPtr(releaseIPAddress)
150+
}
151+
152+
_ = d.Set("release_ip", relaseIPValue)
135153
_ = d.Set("name", res.Name)
136154
_ = d.Set("zone", zone.String())
137155
_ = d.Set("region", region.String())
138156
_ = d.Set("organization_id", res.OrganizationID)
139157
_ = d.Set("project_id", res.ProjectID)
140158
_ = d.Set("tags", res.Tags)
141-
// For now API return lowercase lb type. This should be fix in a near future on the API side
159+
// For now API return lowercase lb type. This should be fixed in a near future on the API side
142160
_ = d.Set("type", strings.ToUpper(res.Type))
143161
_ = d.Set("ip_id", newZonedIDString(zone, res.IP[0].ID))
144162
_ = d.Set("ip_address", res.IP[0].IPAddress)
@@ -160,6 +178,17 @@ func resourceScalewayLbUpdate(ctx context.Context, d *schema.ResourceData, meta
160178
Tags: expandStrings(d.Get("tags")),
161179
}
162180

181+
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
182+
LBID: ID,
183+
Zone: zone,
184+
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
185+
RetryInterval: DefaultWaitRetryInterval,
186+
}, scw.WithContext(ctx))
187+
188+
if err != nil && !is404Error(err) {
189+
return diag.FromErr(err)
190+
}
191+
163192
_, err = lbAPI.UpdateLB(req, scw.WithContext(ctx))
164193
if err != nil {
165194
return diag.FromErr(err)
@@ -175,21 +204,27 @@ func resourceScalewayLbDelete(ctx context.Context, d *schema.ResourceData, meta
175204
return diag.FromErr(err)
176205
}
177206

178-
err = lbAPI.DeleteLB(&lb.ZonedAPIDeleteLBRequest{
179-
Zone: zone,
180-
LBID: ID,
181-
ReleaseIP: false,
207+
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
208+
LBID: ID,
209+
Zone: zone,
210+
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
211+
RetryInterval: DefaultWaitRetryInterval,
182212
}, scw.WithContext(ctx))
183213

184214
if err != nil && !is404Error(err) {
185215
return diag.FromErr(err)
186216
}
187217

188-
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
189-
LBID: ID,
190-
Zone: zone,
191-
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
192-
RetryInterval: DefaultWaitRetryInterval,
218+
var releaseAddressValue bool
219+
releaseIPAddress, releaseIPPExist := d.GetOk("release_ip")
220+
if releaseIPPExist {
221+
releaseAddressValue = *expandBoolPtr(releaseIPAddress)
222+
}
223+
224+
err = lbAPI.DeleteLB(&lb.ZonedAPIDeleteLBRequest{
225+
Zone: zone,
226+
LBID: ID,
227+
ReleaseIP: releaseAddressValue,
193228
}, scw.WithContext(ctx))
194229

195230
if err != nil && !is404Error(err) {

scaleway/resource_lb_acl_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ func TestAccScalewayLbAcl_Basic(t *testing.T) {
188188
}),
189189
),
190190
},
191+
{
192+
Config: `
193+
resource scaleway_lb_ip ip01 {}
194+
`,
195+
Check: resource.ComposeTestCheckFunc(
196+
resource.TestCheckResourceAttrSet("scaleway_lb_ip.ip01", "id"),
197+
),
198+
},
191199
},
192200
})
193201
}

scaleway/resource_lb_backend.go

+12
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
255255
healthCheckPort = d.Get("forward_port").(int)
256256
}
257257

258+
retryInterval := DefaultWaitLBRetryInterval
259+
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
260+
Zone: zone,
261+
LBID: LbID,
262+
Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout),
263+
RetryInterval: &retryInterval,
264+
}, scw.WithContext(ctx))
265+
266+
if err != nil && !is404Error(err) {
267+
return diag.FromErr(err)
268+
}
269+
258270
createReq := &lb.ZonedAPICreateBackendRequest{
259271
Zone: zone,
260272
LBID: LbID,

scaleway/resource_lb_certificate.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ func resourceScalewayLbCertificateCreate(ctx context.Context, d *schema.Resource
124124
return diag.FromErr(err)
125125
}
126126

127+
lbAPI, _, err := lbAPIWithZone(d, meta)
128+
if err != nil {
129+
return diag.FromErr(err)
130+
}
131+
127132
createReq := &lb.ZonedAPICreateCertificateRequest{
128133
Zone: zone,
129134
LBID: lbID,
@@ -135,10 +140,6 @@ func resourceScalewayLbCertificateCreate(ctx context.Context, d *schema.Resource
135140
return diag.FromErr(errors.New("you need to define either letsencrypt or custom_certificate configuration"))
136141
}
137142

138-
lbAPI, _, err := lbAPIWithZone(d, meta)
139-
if err != nil {
140-
return diag.FromErr(err)
141-
}
142143
res, err := lbAPI.CreateCertificate(createReq, scw.WithContext(ctx))
143144
if err != nil {
144145
return diag.FromErr(err)

scaleway/resource_lb_frontend.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,26 @@ func resourceScalewayLbFrontendCreate(ctx context.Context, d *schema.ResourceDat
158158
return diag.FromErr(err)
159159
}
160160

161-
zone, LbID, err := parseZonedID(d.Get("lb_id").(string))
161+
zone, lbID, err := parseZonedID(d.Get("lb_id").(string))
162162
if err != nil {
163163
return diag.FromErr(err)
164164
}
165165

166+
retryInterval := DefaultWaitLBRetryInterval
167+
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
168+
Zone: zone,
169+
LBID: lbID,
170+
Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout),
171+
RetryInterval: &retryInterval,
172+
}, scw.WithContext(ctx))
173+
174+
if err != nil && !is404Error(err) {
175+
return diag.FromErr(err)
176+
}
177+
166178
res, err := lbAPI.CreateFrontend(&lb.ZonedAPICreateFrontendRequest{
167179
Zone: zone,
168-
LBID: LbID,
180+
LBID: lbID,
169181
Name: expandOrGenerateString(d.Get("name"), "lb-frt"),
170182
InboundPort: int32(d.Get("inbound_port").(int)),
171183
BackendID: expandID(d.Get("backend_id")),

scaleway/resource_lb_ip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func resourceScalewayLbIP() *schema.Resource {
4545
"lb_id": {
4646
Type: schema.TypeString,
4747
Computed: true,
48-
Description: "The ID of the loadbalancer attached to this IP, if any",
48+
Description: "The ID of the load balancer attached to this IP, if any",
4949
},
5050
},
5151
}

0 commit comments

Comments
 (0)