Skip to content

Commit 10370a2

Browse files
committed
updated wording + handle 403 on ipam
1 parent 983b8d2 commit 10370a2

File tree

6 files changed

+867
-699
lines changed

6 files changed

+867
-699
lines changed

docs/resources/instance_private_nic.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ In addition to all arguments above, the following attributes are exported:
9393
~> **Important:** Instance private NICs' IDs are [zoned](../guides/regions_and_zones.md#resource-ids), which means they are of the form `{zone}/{id}`, e.g. `fr-par-1/11111111-1111-1111-1111-111111111111`
9494

9595
- `mac_address` - The MAC address of the private NIC.
96-
- `private_ip` - The list of private IPv4 addresses associated with the resource.
97-
- `id` - The ID of the IPv4 address resource.
98-
- `address` - The private IPv4 address.
96+
- `private_ips` - The list of private IPv4 and IPv6 addresses associated with the resource.
97+
- `id` - The ID of the IP address resource.
98+
- `address` - The private IP address.
9999

100100
## Import
101101

docs/resources/instance_server.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ attached to the server. Updates to this field will trigger a stop/start of the s
250250
- `private_network` - (Optional) The private network associated with the server.
251251
Use the `pn_id` key to attach a [private_network](https://www.scaleway.com/en/developers/api/instance/#path-private-nics-list-all-private-nics) on your instance.
252252

253-
- `private_ip` - The list of private IPv4 addresses associated with the resource.
254-
- `id` - The ID of the IPv4 address resource.
255-
- `address` - The private IPv4 address.
253+
- `private_ips` - The list of private IPv4 and IPv6 addresses associated with the resource.
254+
- `id` - The ID of the IP address resource.
255+
- `address` - The private IP address.
256256

257257
- `boot_type` - The boot Type of the server. Possible values are: `local`, `bootscript` or `rescue`.
258258

internal/services/instance/private_nic.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package instance
33
import (
44
"context"
55

6+
"github.com/hashicorp/go-cty/cty"
67
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
89
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -70,21 +71,21 @@ func ResourcePrivateNIC() *schema.Resource {
7071
Description: "IPAM ip list, should be for internal use only",
7172
ForceNew: true,
7273
},
73-
"private_ip": {
74+
"private_ips": {
7475
Type: schema.TypeList,
7576
Computed: true,
76-
Description: "List of private IPv4 addresses associated with the resource",
77+
Description: "List of private IPv4 and IPv6 addresses associated with the resource",
7778
Elem: &schema.Resource{
7879
Schema: map[string]*schema.Schema{
7980
"id": {
8081
Type: schema.TypeString,
8182
Computed: true,
82-
Description: "The ID of the IPv4 address resource",
83+
Description: "The ID of the IP address resource",
8384
},
8485
"address": {
8586
Type: schema.TypeString,
8687
Computed: true,
87-
Description: "The private IPv4 address",
88+
Description: "The private IP address",
8889
},
8990
},
9091
},
@@ -189,21 +190,31 @@ func ResourceInstancePrivateNICRead(ctx context.Context, d *schema.ResourceData,
189190
return diag.FromErr(err)
190191
}
191192

193+
diags := diag.Diagnostics{}
192194
resourceType := ipamAPI.ResourceTypeInstancePrivateNic
193195
opts := &ipam.GetResourcePrivateIPsOptions{
194196
ResourceID: &privateNIC.ID,
195197
ResourceType: &resourceType,
196198
PrivateNetworkID: &privateNIC.PrivateNetworkID,
197199
}
198200

199-
privateIP, err := ipam.GetResourcePrivateIPs(ctx, m, region, opts)
201+
privateIPs, err := ipam.GetResourcePrivateIPs(ctx, m, region, opts)
200202
if err != nil {
201-
return diag.FromErr(err)
203+
if !httperrors.Is403(err) {
204+
return diag.FromErr(err)
205+
}
206+
207+
diags = append(diags, diag.Diagnostic{
208+
Severity: diag.Warning,
209+
Summary: err.Error(),
210+
Detail: "Got 403 while reading private IPs from IPAM API, please check your IAM permissions",
211+
AttributePath: cty.GetAttrPath("private_ips"),
212+
})
202213
}
203214

204-
_ = d.Set("private_ip", privateIP)
215+
_ = d.Set("private_ips", privateIPs)
205216

206-
return nil
217+
return diags
207218
}
208219

209220
func ResourceInstancePrivateNICUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

internal/services/instance/private_nic_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func TestAccPrivateNIC_Basic(t *testing.T) {
4141
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "mac_address"),
4242
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "private_network_id"),
4343
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "server_id"),
44-
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "private_ip.0.id"),
45-
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "private_ip.0.address"),
44+
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "private_ips.0.id"),
45+
resource.TestCheckResourceAttrSet("scaleway_instance_private_nic.nic01", "private_ips.0.address"),
4646
),
4747
},
4848
},

internal/services/instance/server.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
800800
}
801801

802802
allPrivateIPs := []map[string]interface{}(nil)
803+
diags := diag.Diagnostics{}
803804
resourceType := ipamAPI.ResourceTypeInstancePrivateNic
804805

805806
region, err := zone.Region()
@@ -815,7 +816,16 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
815816

816817
privateIPs, err := ipam.GetResourcePrivateIPs(ctx, m, region, opts)
817818
if err != nil {
818-
return diag.FromErr(err)
819+
if !httperrors.Is403(err) {
820+
return diag.FromErr(err)
821+
}
822+
823+
diags = append(diags, diag.Diagnostic{
824+
Severity: diag.Warning,
825+
Summary: err.Error(),
826+
Detail: "Got 403 while reading private IPs from IPAM API, please check your IAM permissions",
827+
AttributePath: cty.GetAttrPath("private_ips"),
828+
})
819829
}
820830

821831
if privateIPs != nil {
@@ -839,7 +849,7 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
839849

840850
mostRelevantTypes := compatibleTypes.CompatibleTypes[:5]
841851

842-
return diag.Diagnostics{diag.Diagnostic{
852+
diags = append(diags, diag.Diagnostic{
843853
Severity: diag.Warning,
844854
Detail: fmt.Sprintf("Instance type %q will soon reach End of Service", server.CommercialType),
845855
Summary: fmt.Sprintf(`Your Instance will soon reach End of Service. You can check the exact date on the Scaleway console. We recommend that you migrate your Instance before that.
@@ -855,10 +865,10 @@ You can check the full list of compatible server types:
855865
server.Zone,
856866
),
857867
AttributePath: cty.GetAttrPath("type"),
858-
}}
868+
})
859869
}
860870

861-
return nil
871+
return diags
862872
}
863873

864874
//gocyclo:ignore

internal/services/ipam/testdata/data-source-ipamip-instance-lb.cassette.yaml

Lines changed: 826 additions & 679 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)