Skip to content

Commit 9ca8ced

Browse files
authored
chore(instance): purge nat information (#2887)
* chore: purge nat information * Fix * Fix
1 parent 75cc56b commit 9ca8ced

File tree

4 files changed

+8
-101
lines changed

4 files changed

+8
-101
lines changed

docs/resources/instance_ip.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ resource "scaleway_instance_ip" "server_ip" {}
1717

1818
The following arguments are supported:
1919

20-
- `type` - (Defaults to `nat`) The type of the IP (`nat`, `routed_ipv4`, `routed_ipv6`), more information in [the documentation](https://www.scaleway.com/en/docs/compute/instances/api-cli/using-routed-ips/)
21-
22-
~> **Important:** An IP can migrate from `nat` to `routed_ipv4` but cannot be converted back
23-
20+
- `type` - The type of the IP (`routed_ipv4`, `routed_ipv6`), more information in [the documentation](https://www.scaleway.com/en/docs/compute/instances/api-cli/using-routed-ips/)
2421
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which the IP should be reserved.
2522
- `project_id` - (Defaults to [provider](../index.md#project_id) `project_id`) The ID of the project the IP is associated with.
2623

internal/services/instance/ip.go

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

6-
"github.com/hashicorp/go-cty/cty"
76
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
98
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -12,6 +11,7 @@ import (
1211
"github.com/scaleway/terraform-provider-scaleway/v2/internal/locality/zonal"
1312
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/account"
1413
"github.com/scaleway/terraform-provider-scaleway/v2/internal/types"
14+
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"
1515
)
1616

1717
func ResourceIP() *schema.Resource {
@@ -39,22 +39,12 @@ func ResourceIP() *schema.Resource {
3939
Description: "The IP prefix",
4040
},
4141
"type": {
42-
Type: schema.TypeString,
43-
Computed: true,
44-
Optional: true,
45-
Description: "The type of instance IP",
46-
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
47-
if i.(string) == "nat" {
48-
return diag.Diagnostics{{
49-
Severity: diag.Error,
50-
Summary: "NAT IPs are not supported anymore",
51-
Detail: "Remove explicit nat configuration, migrate to routed ips or downgrade terraform.\nLearn more about migration: https://www.scaleway.com/en/docs/compute/instances/how-to/migrate-routed-ips/",
52-
AttributePath: path,
53-
}}
54-
}
55-
56-
return nil
57-
},
42+
Type: schema.TypeString,
43+
Computed: true,
44+
Optional: true,
45+
ForceNew: true,
46+
Description: "The type of instance IP",
47+
ValidateDiagFunc: verify.ValidateEnum[instanceSDK.IPType](),
5848
},
5949
"reverse": {
6050
Type: schema.TypeString,
@@ -78,23 +68,6 @@ func ResourceIP() *schema.Resource {
7868
"organization_id": account.OrganizationIDSchema(),
7969
"project_id": account.ProjectIDSchema(),
8070
},
81-
CustomizeDiff: func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
82-
// The only allowed change is
83-
// nat -> routed_ipv4
84-
if diff.HasChange("type") {
85-
before, after := diff.GetChange("type")
86-
oldType := instanceSDK.IPType(before.(string))
87-
newType := instanceSDK.IPType(after.(string))
88-
89-
if oldType == "nat" && newType == "routed_ipv4" {
90-
return nil
91-
}
92-
93-
return diff.ForceNew("type")
94-
}
95-
96-
return nil
97-
},
9871
}
9972
}
10073

@@ -149,10 +122,6 @@ func ResourceInstanceIPUpdate(ctx context.Context, d *schema.ResourceData, m int
149122
req.Tags = types.ExpandUpdatedStringsPtr(d.Get("tags"))
150123
}
151124

152-
if d.HasChange("type") {
153-
req.Type = instanceSDK.IPType(d.Get("type").(string))
154-
}
155-
156125
_, err = instanceAPI.UpdateIP(req, scw.WithContext(ctx))
157126
if err != nil {
158127
return diag.FromErr(err)

internal/services/instance/server.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -340,28 +340,6 @@ func ResourceServer() *schema.Resource {
340340
},
341341
},
342342
},
343-
"routed_ip_enabled": {
344-
Type: schema.TypeBool,
345-
Description: "If server supports routed IPs, default to true",
346-
Optional: true,
347-
Computed: true,
348-
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
349-
if i == nil {
350-
return nil
351-
}
352-
if !i.(bool) {
353-
return diag.Diagnostics{{
354-
Severity: diag.Error,
355-
Summary: "NAT IPs are not supported anymore",
356-
Detail: "Remove explicit disabling, enable it or downgrade terraform.\nLearn more about migration: https://www.scaleway.com/en/docs/compute/instances/how-to/migrate-routed-ips/",
357-
AttributePath: path,
358-
}}
359-
}
360-
361-
return nil
362-
},
363-
Deprecated: "Routed IP is the default configuration, it should always be true",
364-
},
365343
"zone": zonal.Schema(),
366344
"organization_id": account.OrganizationIDSchema(),
367345
"project_id": account.ProjectIDSchema(),
@@ -402,7 +380,6 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
402380
SecurityGroup: types.ExpandStringPtr(zonal.ExpandID(d.Get("security_group_id")).ID),
403381
DynamicIPRequired: scw.BoolPtr(d.Get("enable_dynamic_ip").(bool)),
404382
Tags: types.ExpandStrings(d.Get("tags")),
405-
RoutedIPEnabled: types.ExpandBoolPtr(types.GetBool(d, "routed_ip_enabled")),
406383
}
407384

408385
enableIPv6, ok := d.GetOk("enable_ipv6")
@@ -627,7 +604,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m i
627604
_ = d.Set("enable_dynamic_ip", server.DynamicIPRequired)
628605
_ = d.Set("organization_id", server.Organization)
629606
_ = d.Set("project_id", server.Project)
630-
_ = d.Set("routed_ip_enabled", server.RoutedIPEnabled) //nolint:staticcheck
631607

632608
// Image could be empty in an import context.
633609
image := regional.ExpandID(d.Get("image").(string))
@@ -1037,13 +1013,6 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
10371013
}
10381014
}
10391015

1040-
if d.HasChanges("routed_ip_enabled") {
1041-
err := ResourceInstanceServerEnableRoutedIP(ctx, d, api.API, zone, id)
1042-
if err != nil {
1043-
return diag.FromErr(err)
1044-
}
1045-
}
1046-
10471016
if d.HasChanges("root_volume.0.sbs_iops") {
10481017
warnings = append(warnings, ResourceInstanceServerUpdateRootVolumeIOPS(ctx, api, zone, id, types.ExpandUint32Ptr(d.Get("root_volume.0.sbs_iops")))...)
10491018
}
@@ -1312,29 +1281,6 @@ func ResourceInstanceServerMigrate(ctx context.Context, d *schema.ResourceData,
13121281
return nil
13131282
}
13141283

1315-
func ResourceInstanceServerEnableRoutedIP(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string) error {
1316-
server, err := waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
1317-
if err != nil {
1318-
return err
1319-
}
1320-
1321-
_, err = instanceAPI.ServerAction(&instanceSDK.ServerActionRequest{
1322-
Zone: server.Zone,
1323-
ServerID: server.ID,
1324-
Action: "enable_routed_ip",
1325-
})
1326-
if err != nil {
1327-
return fmt.Errorf("failed to enable routed ip: %w", err)
1328-
}
1329-
1330-
_, err = waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
1331-
if err != nil {
1332-
return err
1333-
}
1334-
1335-
return nil
1336-
}
1337-
13381284
func ResourceInstanceServerUpdateIPs(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string) error {
13391285
server, err := waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
13401286
if err != nil {

internal/services/instance/server_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,6 @@ func TestAccServer_IPs(t *testing.T) {
14611461
}`,
14621462
Check: resource.ComposeTestCheckFunc(
14631463
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
1464-
resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"),
14651464
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"),
14661465
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.id", "scaleway_instance_ip.ip1", "id"),
14671466
),
@@ -1485,7 +1484,6 @@ func TestAccServer_IPs(t *testing.T) {
14851484
}`,
14861485
Check: resource.ComposeTestCheckFunc(
14871486
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
1488-
resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"),
14891487
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "2"),
14901488
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.id", "scaleway_instance_ip.ip1", "id"),
14911489
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.1.id", "scaleway_instance_ip.ip2", "id"),
@@ -1510,7 +1508,6 @@ func TestAccServer_IPs(t *testing.T) {
15101508
}`,
15111509
Check: resource.ComposeTestCheckFunc(
15121510
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
1513-
resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"),
15141511
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"),
15151512
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.id", "scaleway_instance_ip.ip2", "id"),
15161513
),
@@ -1588,7 +1585,6 @@ func TestAccServer_IPsRemoved(t *testing.T) {
15881585
}`,
15891586
Check: resource.ComposeTestCheckFunc(
15901587
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
1591-
resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"),
15921588
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"),
15931589
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.id", "scaleway_instance_ip.main", "id"),
15941590
),
@@ -1608,7 +1604,6 @@ func TestAccServer_IPsRemoved(t *testing.T) {
16081604
Check: resource.ComposeTestCheckFunc(
16091605
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
16101606
serverHasNoIPAssigned(tt, "scaleway_instance_server.main"),
1611-
resource.TestCheckResourceAttr("scaleway_instance_server.main", "routed_ip_enabled", "true"),
16121607
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "0"),
16131608
),
16141609
},

0 commit comments

Comments
 (0)