Skip to content

Commit ab71407

Browse files
committed
updated wording + handle 403 on ipam
1 parent 6fc289e commit ab71407

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

docs/resources/rdb_instance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ are of the form `{region}/{id}`, e.g. `fr-par/11111111-1111-1111-1111-1111111111
238238
- `port` - Port in the Private Network.
239239
- `name` - Name of the endpoint.
240240
- `hostname` - Hostname of the endpoint.
241-
- `private_ip` - The list of private IPv4 addresses associated with the resource.
241+
- `private_ip` - The private IPv4 addresses associated with the resource.
242242
- `id` - The ID of the IPv4 address resource.
243243
- `address` - The private IPv4 address.
244244
- `certificate` - Certificate of the Database Instance.

internal/services/ipam/helpers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010
ipam "github.com/scaleway/scaleway-sdk-go/api/ipam/v1"
1111
"github.com/scaleway/scaleway-sdk-go/scw"
12+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/httperrors"
1213
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/regional"
1314
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1415
)
@@ -103,6 +104,10 @@ func GetResourcePrivateIPs(ctx context.Context, m interface{}, region scw.Region
103104

104105
resp, err := ipamAPI.ListIPs(req, scw.WithContext(ctx))
105106
if err != nil {
107+
if httperrors.Is403(err) {
108+
return nil, err
109+
}
110+
106111
return nil, fmt.Errorf("error fetching IPs from IPAM: %w", err)
107112
}
108113

internal/services/rdb/instance.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88

9+
"github.com/hashicorp/go-cty/cty"
910
"github.com/hashicorp/terraform-plugin-log/tflog"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -324,10 +325,10 @@ func ResourceInstance() *schema.Resource {
324325
Optional: true,
325326
Description: "Enable or disable encryption at rest for the database instance",
326327
},
327-
"private_ips": {
328+
"private_ip": {
328329
Type: schema.TypeList,
329330
Computed: true,
330-
Description: "List of private IPv4 addresses associated with the resource",
331+
Description: "The private IPv4 addresses associated with the resource",
331332
Elem: &schema.Resource{
332333
Schema: map[string]*schema.Schema{
333334
"id": {
@@ -661,7 +662,8 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte
661662
_ = d.Set("logs_policy", flattenInstanceLogsPolicy(res.LogsPolicy))
662663

663664
// set endpoints
664-
var privateIPs []map[string]interface{}
665+
privateIPs := make([]map[string]interface{}, 0, 1)
666+
diags := diag.Diagnostics{}
665667

666668
if pnI, pnExist := flattenPrivateNetwork(res.Endpoints); pnExist {
667669
_ = d.Set("private_network", pnI)
@@ -681,21 +683,30 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte
681683

682684
endpointPrivateIPs, err := ipam.GetResourcePrivateIPs(ctx, m, region, opts)
683685
if err != nil {
684-
return diag.FromErr(err)
686+
if !httperrors.Is403(err) {
687+
return diag.FromErr(err)
688+
}
689+
690+
diags = append(diags, diag.Diagnostic{
691+
Severity: diag.Warning,
692+
Summary: err.Error(),
693+
Detail: "Got 403 while reading private IP from IPAM API, please check your IAM permissions",
694+
AttributePath: cty.GetAttrPath("private_ip"),
695+
})
685696
}
686697

687698
privateIPs = append(privateIPs, endpointPrivateIPs...)
688699
}
689700
}
690701
}
691702

692-
_ = d.Set("private_ips", privateIPs)
703+
_ = d.Set("private_ip", privateIPs)
693704

694705
if lbI, lbExists := flattenLoadBalancer(res.Endpoints); lbExists {
695706
_ = d.Set("load_balancer", lbI)
696707
}
697708

698-
return nil
709+
return diags
699710
}
700711

701712
//gocyclo:ignore

internal/services/rdb/instance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,8 @@ func TestAccInstance_Endpoints(t *testing.T) {
990990
resource.TestCheckResourceAttr("scaleway_rdb_instance.test_endpoints", "load_balancer.#", "0"),
991991
resource.TestCheckResourceAttr("scaleway_rdb_instance.test_endpoints", "endpoint_ip", ""), // Deprecated attribute, might be deleted later
992992
resource.TestCheckResourceAttr("scaleway_rdb_instance.test_endpoints", "endpoint_port", "0"), // Deprecated attribute, might be deleted later
993-
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.test_endpoints", "private_ips.0.id"),
994-
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.test_endpoints", "private_ips.0.address"),
993+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.test_endpoints", "private_ip.0.id"),
994+
resource.TestCheckResourceAttrSet("scaleway_rdb_instance.test_endpoints", "private_ip.0.address"),
995995
),
996996
},
997997
{

0 commit comments

Comments
 (0)