Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: purge nat information
Browse files Browse the repository at this point in the history
remyleone committed Jan 29, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9669d4c commit 9c16a19
Showing 3 changed files with 9 additions and 96 deletions.
5 changes: 1 addition & 4 deletions docs/resources/instance_ip.md
Original file line number Diff line number Diff line change
@@ -17,10 +17,7 @@ resource "scaleway_instance_ip" "server_ip" {}

The following arguments are supported:

- `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/)

~> **Important:** An IP can migrate from `nat` to `routed_ipv4` but cannot be converted back

- `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/)
- `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 IP is associated with.

46 changes: 8 additions & 38 deletions internal/services/instance/ip.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,8 @@ package instance
import (
"context"

"github.com/hashicorp/go-cty/cty"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/verify"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
instanceSDK "github.com/scaleway/scaleway-sdk-go/api/instance/v1"
@@ -39,22 +40,12 @@ func ResourceIP() *schema.Resource {
Description: "The IP prefix",
},
"type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The type of instance IP",
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
if i.(string) == "nat" {
return diag.Diagnostics{{
Severity: diag.Error,
Summary: "NAT IPs are not supported anymore",
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/",
AttributePath: path,
}}
}

return nil
},
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: "The type of instance IP",
ValidateDiagFunc: verify.ValidateEnum[instanceSDK.IPType](),
},
"reverse": {
Type: schema.TypeString,
@@ -78,23 +69,6 @@ func ResourceIP() *schema.Resource {
"organization_id": account.OrganizationIDSchema(),
"project_id": account.ProjectIDSchema(),
},
CustomizeDiff: func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
// The only allowed change is
// nat -> routed_ipv4
if diff.HasChange("type") {
before, after := diff.GetChange("type")
oldType := instanceSDK.IPType(before.(string))
newType := instanceSDK.IPType(after.(string))

if oldType == "nat" && newType == "routed_ipv4" {
return nil
}

return diff.ForceNew("type")
}

return nil
},
}
}

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

if d.HasChange("type") {
req.Type = instanceSDK.IPType(d.Get("type").(string))
}

_, err = instanceAPI.UpdateIP(req, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
54 changes: 0 additions & 54 deletions internal/services/instance/server.go
Original file line number Diff line number Diff line change
@@ -340,28 +340,6 @@ func ResourceServer() *schema.Resource {
},
},
},
"routed_ip_enabled": {
Type: schema.TypeBool,
Description: "If server supports routed IPs, default to true",
Optional: true,
Computed: true,
ValidateDiagFunc: func(i interface{}, path cty.Path) diag.Diagnostics {
if i == nil {
return nil
}
if !i.(bool) {
return diag.Diagnostics{{
Severity: diag.Error,
Summary: "NAT IPs are not supported anymore",
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/",
AttributePath: path,
}}
}

return nil
},
Deprecated: "Routed IP is the default configuration, it should always be true",
},
"zone": zonal.Schema(),
"organization_id": account.OrganizationIDSchema(),
"project_id": account.ProjectIDSchema(),
@@ -402,7 +380,6 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
SecurityGroup: types.ExpandStringPtr(zonal.ExpandID(d.Get("security_group_id")).ID),
DynamicIPRequired: scw.BoolPtr(d.Get("enable_dynamic_ip").(bool)),
Tags: types.ExpandStrings(d.Get("tags")),
RoutedIPEnabled: types.ExpandBoolPtr(types.GetBool(d, "routed_ip_enabled")),
}

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

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

if d.HasChanges("routed_ip_enabled") {
err := ResourceInstanceServerEnableRoutedIP(ctx, d, api.API, zone, id)
if err != nil {
return diag.FromErr(err)
}
}

if d.HasChanges("root_volume.0.sbs_iops") {
warnings = append(warnings, ResourceInstanceServerUpdateRootVolumeIOPS(ctx, api, zone, id, types.ExpandUint32Ptr(d.Get("root_volume.0.sbs_iops")))...)
}
@@ -1312,29 +1281,6 @@ func ResourceInstanceServerMigrate(ctx context.Context, d *schema.ResourceData,
return nil
}

func ResourceInstanceServerEnableRoutedIP(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string) error {
server, err := waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}

_, err = instanceAPI.ServerAction(&instanceSDK.ServerActionRequest{
Zone: server.Zone,
ServerID: server.ID,
Action: "enable_routed_ip",
})
if err != nil {
return fmt.Errorf("failed to enable routed ip: %w", err)
}

_, err = waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return err
}

return nil
}

func ResourceInstanceServerUpdateIPs(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string) error {
server, err := waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
if err != nil {

0 comments on commit 9c16a19

Please sign in to comment.