Skip to content

Commit

Permalink
Add support for LB Private Networks and LB Routes (scaleway#867)
Browse files Browse the repository at this point in the history
* 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 <abarbare@online.net>

* 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 <rleone@scaleway.com>

* chore: add a SECURITY.md (scaleway#872)

* feat(domain): add record resource (scaleway#854)

Co-authored-by: Jeremy JACQUEMIN <jjacquemin@scaleway.com>

* 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 <jjacquemin@scaleway.com>

* doc: fix default runtime on k8s_pool (scaleway#873)

Co-authored-by: Jerome Malinge <jmalinge@online.net>
Co-authored-by: Rémy Léone <rleone@scaleway.com>
Co-authored-by: jerjako <contact@jerjako.com>
Co-authored-by: Jeremy JACQUEMIN <jjacquemin@scaleway.com>
Co-authored-by: Jérémy THERIN <jtherin@users.noreply.github.com>
Co-authored-by: jaime Bernabe <jbernabe@student.42.fr>

* 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 <rleone@scaleway.com>
Co-authored-by: jaime Bernabe <jbernabe@student.42.fr>

* 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 <pub@jeromequere.fr>

* Update scaleway/data_source_lb.go

Co-authored-by: Jerome Quere <pub@jeromequere.fr>

* Update docs/data-sources/lb.md

Co-authored-by: Quentin Brosse <quentin.brosse@icloud.com>

* 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 <pub@jeromequere.fr>
Co-authored-by: Quentin Brosse <quentin.brosse@icloud.com>
Co-authored-by: jaime Bernabe <jbernabe@student.42.fr>
Co-authored-by: Jaime BERNABE <jbernabe@scaleway.com>

* 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 <6184069+Monitob@users.noreply.github.com>
Co-authored-by: Jaime BERNABE <jbernabe@scaleway.com>

* feat(domain): Add domain record data source (scaleway#874)

* feat(domain): Add domain record data source

* fix tests

Co-authored-by: Jeremy JACQUEMIN <jjacquemin@scaleway.com>
Co-authored-by: jaime Bernabe <6184069+Monitob@users.noreply.github.com>

* 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] <support@github.com>

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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rémy Léone <rleone@scaleway.com>

* 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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Rémy Léone <rleone@scaleway.com>

* 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] <support@github.com>

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 <6184069+Monitob@users.noreply.github.com>

* 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] <support@github.com>

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 <github@scaleway.com>

* 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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jaime Bernabe <6184069+Monitob@users.noreply.github.com>

* 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 <rleone@scaleway.com>

* 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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jaime Bernabe <6184069+Monitob@users.noreply.github.com>

* feat(vpcgw): add gateway network resource (scaleway#891)

Co-authored-by: scaleway-bot <github@scaleway.com>

* 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] <support@github.com>

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 <antoinebarbare@gmail.com>
Co-authored-by: Antoine Barbare <abarbare@online.net>
Co-authored-by: Jean-Sébastien Hedde <jshedde@scaleway.com>
Co-authored-by: jerousseau <rousseau.jean.eudes@gmail.com>
Co-authored-by: Rémy Léone <rleone@scaleway.com>
Co-authored-by: jerjako <contact@jerjako.com>
Co-authored-by: Jeremy JACQUEMIN <jjacquemin@scaleway.com>
Co-authored-by: Jérémy THERIN <jtherin@users.noreply.github.com>
Co-authored-by: grom-42 <56079173+grom-42@users.noreply.github.com>
Co-authored-by: Jerome Malinge <jmalinge@online.net>
Co-authored-by: jaime Bernabe <jbernabe@student.42.fr>
Co-authored-by: Jerome Quere <pub@jeromequere.fr>
Co-authored-by: Quentin Brosse <quentin.brosse@icloud.com>
Co-authored-by: Jaime BERNABE <jbernabe@scaleway.com>
Co-authored-by: jaime Bernabe <6184069+Monitob@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alexandre Bouthinon <bouthinon.alexandre@gmail.com>
Co-authored-by: scaleway-bot <github@scaleway.com>
Co-authored-by: LucasBoisserie <LucasBoisserie@users.noreply.github.com>
  • Loading branch information
20 people authored Oct 22, 2021
1 parent c8c49c8 commit 4c22243
Show file tree
Hide file tree
Showing 22 changed files with 5,704 additions and 456 deletions.
4 changes: 4 additions & 0 deletions docs/resources/lb.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ resource "scaleway_lb" "base" {
ip_id = scaleway_lb_ip.ip.id
zone = "fr-par-1"
type = "LB-S"
release_ip = true
}
```

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

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

- `release_ip` - (Defaults to false) The release_ip allow release the ip address associated with the load-balancers.

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

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

Expand Down
69 changes: 69 additions & 0 deletions docs/resources/lb_private_network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
page_title: "Scaleway: scaleway_lb_private_network"
description: |-
Manages Scaleway Load-Balancers private networks
---

# scaleway_lb_private_network

Creates and manages Scaleway attach/detach private networks to Load-Balancers.
For more information, see [the documentation](https://developers.scaleway.com/en/products/lb/zoned_api/#post-d4b30).

## Examples

### Basic

```hcl
resource scaleway_vpc_private_network pn01 {
name = "test-lb-pn"
}
resource scaleway_lb_ip ip01 {}
resource scaleway_lb lb01 {
ip_id = scaleway_lb_ip.ip01.id
name = "test-lb"
type = "lb-s"
release_ip = true
}
resource scaleway_lb_private_network lb01pn01 {
lb_id = scaleway_lb.lb01.id
private_network_id = scaleway_vpc_private_network.pn01.id
static_config = ["172.16.0.100", "172.16.0.101"]
}
```

## Arguments Reference

The following arguments are supported:

- `lb_id` - (Required) The ID of the load-balancer to associate.

- `private_network_id` - (Required) The ID of the Private Network to associate.

- `static_config` - (Required) Define two local ip address of your choice for each load balancer instance. See below.

- `dhcp_config` - (Required) Set to true if you want to let DHCP assign IP addresses. See below.

~> **Important:** Only one of static_config and dhcp_config may be set.

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

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

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

- `status` - The Private Network attachment status

## Import

Load-Balancer private network can be imported using the `{zone}/{id}`, e.g.

```bash
$ terraform import scaleway_lb_private_network.lb01pn01 fr-par/11111111-1111-1111-1111-111111111111
```

The attachments can either be found in the console
16 changes: 16 additions & 0 deletions scaleway/data_source_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func dataSourceScalewayLb() *schema.Resource {
ValidateFunc: validationUUIDorUUIDWithLocality(),
ConflictsWith: []string{"name"},
}
dsSchema["release_ip"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Release the IPs related to this load-balancer",
}

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

var relaseIPValue bool
releaseIPAddress, releaseIPExist := d.GetOk("release_ip")
if releaseIPExist {
relaseIPValue = *expandBoolPtr(releaseIPAddress)
}

err = d.Set("release_ip", relaseIPValue)
if err != nil {
return diag.FromErr(err)
}
zonedID := datasourceNewZonedID(lbID, zone)
d.SetId(zonedID)
err = d.Set("lb_id", zonedID)
Expand Down
24 changes: 24 additions & 0 deletions scaleway/helpers_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,27 @@ func lbUpgradeV1RegionalToZonedID(element string) (string, error) {
// append zone 1 as default: e.g. fr-par-1
return fmt.Sprintf("%s-1/%s", locality, id), nil
}

func expandLbPrivateNetworkStaticConfig(raw interface{}) *lb.PrivateNetworkStaticConfig {
if raw == nil || len(raw.([]interface{})) < 1 {
return nil
}
return &lb.PrivateNetworkStaticConfig{
IPAddress: expandStrings(raw),
}
}

func flattenLbPrivateNetworkStaticConfig(cfg *lb.PrivateNetworkStaticConfig) []string {
if cfg == nil {
return nil
}

return cfg.IPAddress
}

func expandLbPrivateNetworkDHCPConfig(raw interface{}) *lb.PrivateNetworkDHCPConfig {
if raw == nil || !raw.(bool) {
return nil
}
return &lb.PrivateNetworkDHCPConfig{}
}
2 changes: 2 additions & 0 deletions scaleway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func Provider(config *ProviderConfig) plugin.ProviderFunc {
"scaleway_lb_backend": resourceScalewayLbBackend(),
"scaleway_lb_certificate": resourceScalewayLbCertificate(),
"scaleway_lb_frontend": resourceScalewayLbFrontend(),
"scaleway_lb_private_network": resourceScalewayLbPrivateNetwork(),
"scaleway_lb_route": resourceScalewayLbRoute(),
"scaleway_registry_namespace": resourceScalewayRegistryNamespace(),
"scaleway_rdb_acl": resourceScalewayRdbACL(),
"scaleway_rdb_database": resourceScalewayRdbDatabase(),
Expand Down
2 changes: 1 addition & 1 deletion scaleway/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type TestTools struct {
}

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

Expand Down
55 changes: 45 additions & 10 deletions scaleway/resource_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package scaleway
import (
"context"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/api/lb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

const (
DefaultWaitLBRetryInterval = 30 * time.Second
)

func resourceScalewayLb() *schema.Resource {
return &schema.Resource{
CreateContext: resourceScalewayLbCreate,
Expand Down Expand Up @@ -60,6 +65,12 @@ func resourceScalewayLb() *schema.Resource {
Computed: true,
Description: "The load-balance public IP address",
},
"release_ip": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Release the IPs related to this load-balancer",
},
"region": regionComputedSchema(),
"zone": zoneSchema(),
"organization_id": organizationIDSchema(),
Expand Down Expand Up @@ -132,13 +143,20 @@ func resourceScalewayLbRead(ctx context.Context, d *schema.ResourceData, meta in
return diag.FromErr(err)
}

var relaseIPValue bool
releaseIPAddress, releaseIPPExist := d.GetOk("release_ip")
if releaseIPPExist {
relaseIPValue = *expandBoolPtr(releaseIPAddress)
}

_ = d.Set("release_ip", relaseIPValue)
_ = d.Set("name", res.Name)
_ = d.Set("zone", zone.String())
_ = d.Set("region", region.String())
_ = d.Set("organization_id", res.OrganizationID)
_ = d.Set("project_id", res.ProjectID)
_ = d.Set("tags", res.Tags)
// For now API return lowercase lb type. This should be fix in a near future on the API side
// For now API return lowercase lb type. This should be fixed in a near future on the API side
_ = d.Set("type", strings.ToUpper(res.Type))
_ = d.Set("ip_id", newZonedIDString(zone, res.IP[0].ID))
_ = d.Set("ip_address", res.IP[0].IPAddress)
Expand All @@ -160,6 +178,17 @@ func resourceScalewayLbUpdate(ctx context.Context, d *schema.ResourceData, meta
Tags: expandStrings(d.Get("tags")),
}

_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
LBID: ID,
Zone: zone,
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
RetryInterval: DefaultWaitRetryInterval,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
return diag.FromErr(err)
}

_, err = lbAPI.UpdateLB(req, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
Expand All @@ -175,21 +204,27 @@ func resourceScalewayLbDelete(ctx context.Context, d *schema.ResourceData, meta
return diag.FromErr(err)
}

err = lbAPI.DeleteLB(&lb.ZonedAPIDeleteLBRequest{
Zone: zone,
LBID: ID,
ReleaseIP: false,
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
LBID: ID,
Zone: zone,
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
RetryInterval: DefaultWaitRetryInterval,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
return diag.FromErr(err)
}

_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
LBID: ID,
Zone: zone,
Timeout: scw.TimeDurationPtr(LbWaitForTimeout),
RetryInterval: DefaultWaitRetryInterval,
var releaseAddressValue bool
releaseIPAddress, releaseIPPExist := d.GetOk("release_ip")
if releaseIPPExist {
releaseAddressValue = *expandBoolPtr(releaseIPAddress)
}

err = lbAPI.DeleteLB(&lb.ZonedAPIDeleteLBRequest{
Zone: zone,
LBID: ID,
ReleaseIP: releaseAddressValue,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
Expand Down
8 changes: 8 additions & 0 deletions scaleway/resource_lb_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func TestAccScalewayLbAcl_Basic(t *testing.T) {
}),
),
},
{
Config: `
resource scaleway_lb_ip ip01 {}
`,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("scaleway_lb_ip.ip01", "id"),
),
},
},
})
}
Expand Down
12 changes: 12 additions & 0 deletions scaleway/resource_lb_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ func resourceScalewayLbBackendCreate(ctx context.Context, d *schema.ResourceData
healthCheckPort = d.Get("forward_port").(int)
}

retryInterval := DefaultWaitLBRetryInterval
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
Zone: zone,
LBID: LbID,
Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout),
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
return diag.FromErr(err)
}

createReq := &lb.ZonedAPICreateBackendRequest{
Zone: zone,
LBID: LbID,
Expand Down
9 changes: 5 additions & 4 deletions scaleway/resource_lb_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func resourceScalewayLbCertificateCreate(ctx context.Context, d *schema.Resource
return diag.FromErr(err)
}

lbAPI, _, err := lbAPIWithZone(d, meta)
if err != nil {
return diag.FromErr(err)
}

createReq := &lb.ZonedAPICreateCertificateRequest{
Zone: zone,
LBID: lbID,
Expand All @@ -135,10 +140,6 @@ func resourceScalewayLbCertificateCreate(ctx context.Context, d *schema.Resource
return diag.FromErr(errors.New("you need to define either letsencrypt or custom_certificate configuration"))
}

lbAPI, _, err := lbAPIWithZone(d, meta)
if err != nil {
return diag.FromErr(err)
}
res, err := lbAPI.CreateCertificate(createReq, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
Expand Down
16 changes: 14 additions & 2 deletions scaleway/resource_lb_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,26 @@ func resourceScalewayLbFrontendCreate(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(err)
}

zone, LbID, err := parseZonedID(d.Get("lb_id").(string))
zone, lbID, err := parseZonedID(d.Get("lb_id").(string))
if err != nil {
return diag.FromErr(err)
}

retryInterval := DefaultWaitLBRetryInterval
_, err = lbAPI.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
Zone: zone,
LBID: lbID,
Timeout: scw.TimeDurationPtr(defaultInstanceServerWaitTimeout),
RetryInterval: &retryInterval,
}, scw.WithContext(ctx))

if err != nil && !is404Error(err) {
return diag.FromErr(err)
}

res, err := lbAPI.CreateFrontend(&lb.ZonedAPICreateFrontendRequest{
Zone: zone,
LBID: LbID,
LBID: lbID,
Name: expandOrGenerateString(d.Get("name"), "lb-frt"),
InboundPort: int32(d.Get("inbound_port").(int)),
BackendID: expandID(d.Get("backend_id")),
Expand Down
2 changes: 1 addition & 1 deletion scaleway/resource_lb_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func resourceScalewayLbIP() *schema.Resource {
"lb_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the loadbalancer attached to this IP, if any",
Description: "The ID of the load balancer attached to this IP, if any",
},
},
}
Expand Down
Loading

0 comments on commit 4c22243

Please sign in to comment.