diff --git a/docs/resources/instance_ip.md b/docs/resources/instance_ip.md index 1caf28df9..154737f67 100644 --- a/docs/resources/instance_ip.md +++ b/docs/resources/instance_ip.md @@ -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. diff --git a/internal/services/instance/ip.go b/internal/services/instance/ip.go index ef2c35964..266541603 100644 --- a/internal/services/instance/ip.go +++ b/internal/services/instance/ip.go @@ -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) diff --git a/internal/services/instance/server.go b/internal/services/instance/server.go index 0178efd8b..507e5cbef 100644 --- a/internal/services/instance/server.go +++ b/internal/services/instance/server.go @@ -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 {