Skip to content

Commit 5a02c5d

Browse files
committed
feat(instance): server: remove deprecated IP fields
1 parent 8d8b8cc commit 5a02c5d

File tree

6 files changed

+35
-213
lines changed

6 files changed

+35
-213
lines changed

docs/resources/instance_server.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ attached to the server. Updates to this field will trigger a stop/start of the s
227227

228228
~> **Important:** If this field contains local volumes, you have to first detach them, in one apply, and then delete the volume in another apply.
229229

230-
- `enable_ipv6` - (Defaults to `false`) Determines if IPv6 is enabled for the server.
231-
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
232-
233230
- `ip_id` - (Optional) The ID of the reserved IP that is attached to the server.
234231

235232
- `ip_ids` - (Optional) List of ID of reserved IPs that are attached to the server. Cannot be used with `ip_id`.
@@ -302,12 +299,6 @@ In addition to all arguments above, the following attributes are exported:
302299
- `family` - The IP address' family.
303300
- `dynamic` - Whether the IP is dynamic.
304301
- `provisioning_mode` - The provisioning mode of the IP
305-
- `ipv6_address` - The default ipv6 address routed to the server. ( Only set when enable_ipv6 is set to true )
306-
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
307-
- `ipv6_gateway` - The ipv6 gateway address. ( Only set when enable_ipv6 is set to true )
308-
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
309-
- `ipv6_prefix_length` - The prefix length of the ipv6 subnet routed to the server. ( Only set when enable_ipv6 is set to true )
310-
Deprecated: Please use a scaleway_instance_ip with a `routed_ipv6` type.
311302
- `boot_type` - The boot Type of the server. Possible values are: `local`, `bootscript` or `rescue`.
312303
- `organization_id` - The organization ID the server is associated with.
313304

internal/services/instance/ip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ func TestAccIP_RoutedIPV6_Attached(t *testing.T) {
134134
defer tt.Cleanup()
135135

136136
resource.ParallelTest(t, resource.TestCase{
137-
ProviderFactories: tt.ProviderFactories,
138-
CheckDestroy: instancechecks.IsIPDestroyed(tt),
137+
ProtoV6ProviderFactories: tt.ProviderFactories,
138+
CheckDestroy: instancechecks.IsIPDestroyed(tt),
139139
Steps: []resource.TestStep{
140140
{
141141
Config: `

internal/services/instance/server.go

Lines changed: 28 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,6 @@ func ResourceServer() *schema.Resource {
192192
Optional: true,
193193
Description: "The additional volumes attached to the server",
194194
},
195-
"enable_ipv6": {
196-
Type: schema.TypeBool,
197-
Optional: true,
198-
Default: false,
199-
Description: "Determines if IPv6 is enabled for the server",
200-
Deprecated: "Please use a scaleway_instance_ip with a `routed_ipv6` type",
201-
},
202-
"private_ip": {
203-
Type: schema.TypeString,
204-
Computed: true,
205-
Description: "The Scaleway internal IP address of the server",
206-
Deprecated: "Use ipam_ip datasource instead to fetch your server's IP in your private network.",
207-
},
208-
"public_ip": {
209-
Type: schema.TypeString,
210-
Computed: true,
211-
Description: "The public IPv4 address of the server",
212-
Deprecated: "Use public_ips instead",
213-
},
214195
"ip_id": {
215196
Type: schema.TypeString,
216197
Optional: true,
@@ -229,24 +210,6 @@ func ResourceServer() *schema.Resource {
229210
DiffSuppressFunc: dsf.Locality,
230211
},
231212
},
232-
"ipv6_address": {
233-
Type: schema.TypeString,
234-
Computed: true,
235-
Description: "The default public IPv6 address routed to the server.",
236-
Deprecated: "Please use a scaleway_instance_ip with a `routed_ipv6` type",
237-
},
238-
"ipv6_gateway": {
239-
Type: schema.TypeString,
240-
Computed: true,
241-
Description: "The IPv6 gateway address",
242-
Deprecated: "Please use a scaleway_instance_ip with a `routed_ipv6` type",
243-
},
244-
"ipv6_prefix_length": {
245-
Type: schema.TypeInt,
246-
Computed: true,
247-
Deprecated: "Please use a scaleway_instance_ip with a `routed_ipv6` type",
248-
Description: "The IPv6 prefix length routed to the server.",
249-
},
250213
"enable_dynamic_ip": {
251214
Type: schema.TypeBool,
252215
Optional: true,
@@ -449,21 +412,14 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
449412
Protected: d.Get("protected").(bool),
450413
}
451414

452-
enableIPv6, ok := d.GetOk("enable_ipv6")
453-
if ok {
454-
req.EnableIPv6 = scw.BoolPtr(enableIPv6.(bool)) //nolint:staticcheck
455-
}
456-
457415
if bootType, ok := d.GetOk("boot_type"); ok {
458416
bootType := instanceSDK.BootType(bootType.(string))
459417
req.BootType = &bootType
460418
}
461419

462420
if ipID, ok := d.GetOk("ip_id"); ok {
463-
req.PublicIP = types.ExpandStringPtr(zonal.ExpandID(ipID).ID) //nolint:staticcheck
464-
}
465-
466-
if ipIDs, ok := d.GetOk("ip_ids"); ok {
421+
req.PublicIPs = &[]string{zonal.ExpandID(ipID).ID}
422+
} else if ipIDs, ok := d.GetOk("ip_ids"); ok {
467423
req.PublicIPs = types.ExpandSliceIDsPtr(ipIDs)
468424
}
469425

@@ -680,8 +636,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
680636
}
681637

682638
_ = d.Set("security_group_id", zonal.NewID(zone, server.SecurityGroup.ID).String())
683-
// EnableIPv6 is deprecated
684-
_ = d.Set("enable_ipv6", server.EnableIPv6) //nolint:staticcheck
685639
_ = d.Set("enable_dynamic_ip", server.DynamicIPRequired)
686640
_ = d.Set("organization_id", server.Organization)
687641
_ = d.Set("project_id", server.Project)
@@ -698,35 +652,26 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
698652
_ = d.Set("placement_group_policy_respected", server.PlacementGroup.PolicyRespected)
699653
}
700654

701-
if server.PrivateIP != nil {
702-
_ = d.Set("private_ip", types.FlattenStringPtr(server.PrivateIP))
703-
}
704-
705-
if _, hasIPID := d.GetOk("ip_id"); server.PublicIP != nil && hasIPID { //nolint:staticcheck
706-
if !server.PublicIP.Dynamic { //nolint:staticcheck
707-
_ = d.Set("ip_id", zonal.NewID(zone, server.PublicIP.ID).String()) //nolint:staticcheck
655+
if ipID, hasIPID := d.GetOk("ip_id"); hasIPID {
656+
publicIP := FindIPInList(ipID.(string), server.PublicIPs)
657+
if publicIP != nil && !publicIP.Dynamic {
658+
_ = d.Set("ip_id", zonal.NewID(zone, publicIP.ID).String())
708659
} else {
709660
_ = d.Set("ip_id", "")
710661
}
711662
} else {
712663
_ = d.Set("ip_id", "")
713664
}
714665

715-
if server.PublicIP != nil { //nolint:staticcheck
716-
_ = d.Set("public_ip", server.PublicIP.Address.String()) //nolint:staticcheck
666+
if len(server.PublicIPs) > 0 {
667+
_ = d.Set("public_ips", flattenServerPublicIPs(server.Zone, server.PublicIPs))
717668
d.SetConnInfo(map[string]string{
718669
"type": "ssh",
719-
"host": server.PublicIP.Address.String(), //nolint:staticcheck
670+
"host": server.PublicIPs[0].Address.String(),
720671
})
721-
} else {
722-
_ = d.Set("public_ip", "")
723-
d.SetConnInfo(nil)
724-
}
725-
726-
if len(server.PublicIPs) > 0 {
727-
_ = d.Set("public_ips", flattenServerPublicIPs(server.Zone, server.PublicIPs))
728672
} else {
729673
_ = d.Set("public_ips", []any{})
674+
d.SetConnInfo(nil)
730675
}
731676

732677
if _, hasIPIDs := d.GetOk("ip_ids"); hasIPIDs {
@@ -735,22 +680,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
735680
_ = d.Set("ip_ids", []any{})
736681
}
737682

738-
if server.IPv6 != nil { //nolint:staticcheck
739-
_ = d.Set("ipv6_address", server.IPv6.Address.String()) //nolint:staticcheck
740-
_ = d.Set("ipv6_gateway", server.IPv6.Gateway.String()) //nolint:staticcheck
741-
742-
prefixLength, err := strconv.Atoi(server.IPv6.Netmask) //nolint:staticcheck
743-
if err != nil {
744-
return diag.FromErr(err)
745-
}
746-
747-
_ = d.Set("ipv6_prefix_length", prefixLength)
748-
} else {
749-
_ = d.Set("ipv6_address", nil)
750-
_ = d.Set("ipv6_gateway", nil)
751-
_ = d.Set("ipv6_prefix_length", nil)
752-
}
753-
754683
if server.AdminPasswordEncryptionSSHKeyID != nil {
755684
_ = d.Set("admin_password_encryption_ssh_key_id", server.AdminPasswordEncryptionSSHKeyID)
756685
}
@@ -973,11 +902,6 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
973902
}
974903
}
975904

976-
if d.HasChange("enable_ipv6") {
977-
serverShouldUpdate = true
978-
updateRequest.EnableIPv6 = scw.BoolPtr(d.Get("enable_ipv6").(bool))
979-
}
980-
981905
if d.HasChange("enable_dynamic_ip") {
982906
serverShouldUpdate = true
983907
updateRequest.DynamicIPRequired = scw.BoolPtr(d.Get("enable_dynamic_ip").(bool))
@@ -1022,53 +946,21 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
1022946
// Update reserved IP
1023947
////
1024948
if d.HasChange("ip_id") && !instanceIPHasMigrated(d) {
1025-
server, err := waitForServer(ctx, api.API, zone, id, d.Timeout(schema.TimeoutUpdate))
1026-
if err != nil {
1027-
return diag.FromErr(err)
1028-
}
1029-
1030949
ipID := zonal.ExpandID(d.Get("ip_id")).ID
1031-
// If an IP is already attached, and it's not a dynamic IP we detach it.
1032-
if server.PublicIP != nil && !server.PublicIP.Dynamic { //nolint:staticcheck
1033-
_, err = api.UpdateIP(&instanceSDK.UpdateIPRequest{
1034-
Zone: zone,
1035-
IP: server.PublicIP.ID, //nolint:staticcheck
1036-
Server: &instanceSDK.NullableStringValue{Null: true},
1037-
})
1038-
if err != nil {
1039-
return diag.FromErr(err)
1040-
}
1041-
// we wait to ensure to not detach the new ip.
1042-
_, err := waitForServer(ctx, api.API, zone, id, d.Timeout(schema.TimeoutUpdate))
1043-
if err != nil {
1044-
return diag.FromErr(err)
1045-
}
1046-
}
1047-
// If a new IP is provided, we attach it to the server
1048-
if ipID != "" {
1049-
_, err := waitForServer(ctx, api.API, zone, id, d.Timeout(schema.TimeoutUpdate))
1050-
if err != nil {
1051-
return diag.FromErr(err)
1052-
}
1053-
1054-
_, err = api.UpdateIP(&instanceSDK.UpdateIPRequest{
1055-
Zone: zone,
1056-
IP: ipID,
1057-
Server: &instanceSDK.NullableStringValue{Value: id},
1058-
}, scw.WithContext(ctx))
1059-
if err != nil {
1060-
return diag.FromErr(err)
1061-
}
1062-
1063-
_, err = waitForServer(ctx, api.API, zone, id, d.Timeout(schema.TimeoutUpdate))
950+
if ipID == "" {
951+
emptyIPList := make([]string, 0)
952+
updateRequest.PublicIPs = &emptyIPList
953+
serverShouldUpdate = true
954+
} else {
955+
err := ResourceInstanceServerUpdateIPs(ctx, d, api.API, zone, id, "ip_id")
1064956
if err != nil {
1065957
return diag.FromErr(err)
1066958
}
1067959
}
1068960
}
1069961

1070962
if d.HasChange("ip_ids") {
1071-
err := ResourceInstanceServerUpdateIPs(ctx, d, api.API, zone, id)
963+
err := ResourceInstanceServerUpdateIPs(ctx, d, api.API, zone, id, "ip_ids")
1072964
if err != nil {
1073965
return diag.FromErr(err)
1074966
}
@@ -1535,13 +1427,22 @@ func ResourceInstanceServerMigrate(ctx context.Context, d *schema.ResourceData,
15351427
return nil
15361428
}
15371429

1538-
func ResourceInstanceServerUpdateIPs(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string) error {
1430+
func ResourceInstanceServerUpdateIPs(ctx context.Context, d *schema.ResourceData, instanceAPI *instanceSDK.API, zone scw.Zone, id string, attribute string) error {
15391431
server, err := waitForServer(ctx, instanceAPI, zone, id, d.Timeout(schema.TimeoutUpdate))
15401432
if err != nil {
15411433
return err
15421434
}
15431435

1544-
schemaIPs := d.Get("ip_ids").([]any)
1436+
var schemaIPs []any
1437+
1438+
switch attribute {
1439+
case "ip_id":
1440+
schemaIP := d.Get(attribute).(string)
1441+
schemaIPs = append(schemaIPs, schemaIP)
1442+
case "ip_ids":
1443+
schemaIPs = d.Get(attribute).([]any)
1444+
}
1445+
15451446
requestedIPs := make(map[string]bool, len(schemaIPs))
15461447

15471448
// Gather request IPs in a map

internal/services/instance/server_test.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,6 @@ func TestAccServer_Ipv6(t *testing.T) {
786786
`,
787787
Check: resource.ComposeTestCheckFunc(
788788
isServerPresent(tt, "scaleway_instance_server.server01"),
789-
resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_address", ""),
790-
resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_gateway", ""),
791-
resource.TestCheckResourceAttr("scaleway_instance_server.server01", "ipv6_prefix_length", "0"),
792789
resource.TestCheckResourceAttr("scaleway_instance_server.server01", "public_ips.#", "0"),
793790
),
794791
},
@@ -848,7 +845,7 @@ func TestAccServer_WithReservedIP(t *testing.T) {
848845
`,
849846
Check: resource.ComposeTestCheckFunc(
850847
isServerPresent(tt, "scaleway_instance_server.base"),
851-
resource.TestCheckResourceAttrPair("scaleway_instance_ip.first", "address", "scaleway_instance_server.base", "public_ip"), // public_ip is deprecated
848+
resource.TestCheckResourceAttrPair("scaleway_instance_ip.first", "address", "scaleway_instance_server.base", "public_ips.0.address"),
852849
resource.TestCheckResourceAttrPair("scaleway_instance_ip.first", "id", "scaleway_instance_server.base", "ip_id"),
853850
),
854851
},
@@ -866,7 +863,7 @@ func TestAccServer_WithReservedIP(t *testing.T) {
866863
Check: resource.ComposeTestCheckFunc(
867864
isServerPresent(tt, "scaleway_instance_server.base"),
868865
isIPAttachedToServer(tt, "scaleway_instance_ip.second", "scaleway_instance_server.base"),
869-
resource.TestCheckResourceAttrPair("scaleway_instance_ip.second", "address", "scaleway_instance_server.base", "public_ip"),
866+
resource.TestCheckResourceAttrPair("scaleway_instance_ip.second", "address", "scaleway_instance_server.base", "public_ips.0.address"),
870867
resource.TestCheckResourceAttrPair("scaleway_instance_ip.second", "id", "scaleway_instance_server.base", "ip_id"),
871868
),
872869
},
@@ -883,7 +880,7 @@ func TestAccServer_WithReservedIP(t *testing.T) {
883880
Check: resource.ComposeTestCheckFunc(
884881
isServerPresent(tt, "scaleway_instance_server.base"),
885882
serverHasNoIPAssigned(tt, "scaleway_instance_server.base"),
886-
resource.TestCheckResourceAttr("scaleway_instance_server.base", "public_ip", ""),
883+
resource.TestCheckResourceAttr("scaleway_instance_server.base", "public_ips.#", "0"),
887884
resource.TestCheckResourceAttr("scaleway_instance_server.base", "ip_id", ""),
888885
),
889886
},
@@ -901,7 +898,7 @@ func TestAccServer_WithReservedIP(t *testing.T) {
901898
Check: resource.ComposeTestCheckFunc(
902899
isServerPresent(tt, "scaleway_instance_server.base"),
903900
serverHasNoIPAssigned(tt, "scaleway_instance_server.base"),
904-
acctest.CheckResourceAttrIPv4("scaleway_instance_server.base", "public_ip"),
901+
acctest.CheckResourceAttrIPv4("scaleway_instance_server.base", "public_ips.0.address"),
905902
resource.TestCheckResourceAttr("scaleway_instance_server.base", "ip_id", ""),
906903
),
907904
},
@@ -983,7 +980,7 @@ func serverHasNewVolume(_ *acctest.TestTools, n string) resource.TestCheckFunc {
983980

984981
rootVolumeName, ok := rs.Primary.Attributes["root_volume.0.name"]
985982
if !ok {
986-
return errors.New("instanceSDK root_volume has no name")
983+
return errors.New("instance root_volume has no name")
987984
}
988985

989986
if strings.HasPrefix(rootVolumeName, "tf") {
@@ -1638,7 +1635,6 @@ func TestAccServer_IPRemoved(t *testing.T) {
16381635
arePrivateNICsPresent(tt, "scaleway_instance_server.main"),
16391636
resource.TestCheckResourceAttr("scaleway_instance_server.main", "public_ips.#", "1"),
16401637
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.id", "scaleway_instance_ip.main", "id"),
1641-
resource.TestCheckResourceAttrPair("scaleway_instance_server.main", "public_ips.0.address", "scaleway_instance_server.main", "public_ip"),
16421638
),
16431639
},
16441640
{

0 commit comments

Comments
 (0)