Skip to content

Commit 6a47f13

Browse files
committed
feat(instance): server: remove deprecated IP fields
1 parent 0abaa5d commit 6a47f13

File tree

5 files changed

+25
-100
lines changed

5 files changed

+25
-100
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/helpers_instance.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,3 +599,14 @@ func DeleteASGServers(
599599

600600
return nil
601601
}
602+
603+
// FindIPInList looks for an IP in a list to avoid using the deprecated server.PublicIP field
604+
func FindIPInList(ipID string, ips []*instance.ServerIP) *instance.ServerIP {
605+
id := zonal.ExpandID(ipID).ID
606+
for _, ip := range ips {
607+
if ip.ID == id {
608+
return ip
609+
}
610+
}
611+
return nil
612+
}

internal/services/instance/server.go

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -192,25 +192,12 @@ 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-
},
202195
"private_ip": {
203196
Type: schema.TypeString,
204197
Computed: true,
205198
Description: "The Scaleway internal IP address of the server",
206199
Deprecated: "Use ipam_ip datasource instead to fetch your server's IP in your private network.",
207200
},
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-
},
214201
"ip_id": {
215202
Type: schema.TypeString,
216203
Optional: true,
@@ -229,24 +216,6 @@ func ResourceServer() *schema.Resource {
229216
DiffSuppressFunc: dsf.Locality,
230217
},
231218
},
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-
},
250219
"enable_dynamic_ip": {
251220
Type: schema.TypeBool,
252221
Optional: true,
@@ -449,21 +418,14 @@ func ResourceInstanceServerCreate(ctx context.Context, d *schema.ResourceData, m
449418
Protected: d.Get("protected").(bool),
450419
}
451420

452-
enableIPv6, ok := d.GetOk("enable_ipv6")
453-
if ok {
454-
req.EnableIPv6 = scw.BoolPtr(enableIPv6.(bool)) //nolint:staticcheck
455-
}
456-
457421
if bootType, ok := d.GetOk("boot_type"); ok {
458422
bootType := instanceSDK.BootType(bootType.(string))
459423
req.BootType = &bootType
460424
}
461425

462426
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 {
427+
req.PublicIPs = &[]string{zonal.ExpandID(ipID).ID}
428+
} else if ipIDs, ok := d.GetOk("ip_ids"); ok {
467429
req.PublicIPs = types.ExpandSliceIDsPtr(ipIDs)
468430
}
469431

@@ -680,8 +642,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
680642
}
681643

682644
_ = 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
685645
_ = d.Set("enable_dynamic_ip", server.DynamicIPRequired)
686646
_ = d.Set("organization_id", server.Organization)
687647
_ = d.Set("project_id", server.Project)
@@ -702,31 +662,26 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
702662
_ = d.Set("private_ip", types.FlattenStringPtr(server.PrivateIP))
703663
}
704664

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
665+
if ipID, hasIPID := d.GetOk("ip_id"); hasIPID {
666+
publicIP := FindIPInList(ipID.(string), server.PublicIPs)
667+
if publicIP != nil && !publicIP.Dynamic {
668+
_ = d.Set("ip_id", zonal.NewID(zone, publicIP.ID).String())
708669
} else {
709670
_ = d.Set("ip_id", "")
710671
}
711672
} else {
712673
_ = d.Set("ip_id", "")
713674
}
714675

715-
if server.PublicIP != nil { //nolint:staticcheck
716-
_ = d.Set("public_ip", server.PublicIP.Address.String()) //nolint:staticcheck
676+
if len(server.PublicIPs) > 0 {
677+
_ = d.Set("public_ips", flattenServerPublicIPs(server.Zone, server.PublicIPs))
717678
d.SetConnInfo(map[string]string{
718679
"type": "ssh",
719-
"host": server.PublicIP.Address.String(), //nolint:staticcheck
680+
"host": server.PublicIPs[0].Address.String(),
720681
})
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))
728682
} else {
729683
_ = d.Set("public_ips", []any{})
684+
d.SetConnInfo(nil)
730685
}
731686

732687
if _, hasIPIDs := d.GetOk("ip_ids"); hasIPIDs {
@@ -735,22 +690,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
735690
_ = d.Set("ip_ids", []any{})
736691
}
737692

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-
754693
if server.AdminPasswordEncryptionSSHKeyID != nil {
755694
_ = d.Set("admin_password_encryption_ssh_key_id", server.AdminPasswordEncryptionSSHKeyID)
756695
}
@@ -973,11 +912,6 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
973912
}
974913
}
975914

976-
if d.HasChange("enable_ipv6") {
977-
serverShouldUpdate = true
978-
updateRequest.EnableIPv6 = scw.BoolPtr(d.Get("enable_ipv6").(bool))
979-
}
980-
981915
if d.HasChange("enable_dynamic_ip") {
982916
serverShouldUpdate = true
983917
updateRequest.DynamicIPRequired = scw.BoolPtr(d.Get("enable_dynamic_ip").(bool))
@@ -1028,10 +962,11 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
1028962

1029963
ipID := zonal.ExpandID(d.Get("ip_id")).ID
1030964
// If an IP is already attached, and it's not a dynamic IP we detach it.
1031-
if server.PublicIP != nil && !server.PublicIP.Dynamic { //nolint:staticcheck
965+
publicIP := FindIPInList(ipID, server.PublicIPs)
966+
if publicIP != nil && !publicIP.Dynamic {
1032967
_, err = api.UpdateIP(&instanceSDK.UpdateIPRequest{
1033968
Zone: zone,
1034-
IP: server.PublicIP.ID, //nolint:staticcheck
969+
IP: publicIP.ID,
1035970
Server: &instanceSDK.NullableStringValue{Null: true},
1036971
})
1037972
if err != nil {

internal/services/instance/servers_data_source.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,8 @@ func DataSourceInstanceServersRead(ctx context.Context, d *schema.ResourceData,
212212
rawServer := make(map[string]any)
213213
rawServer["id"] = zonal.NewID(server.Zone, server.ID).String()
214214

215-
if server.PublicIP != nil { //nolint:staticcheck
216-
rawServer["public_ip"] = server.PublicIP.Address.String() //nolint:staticcheck
217-
}
218-
219215
if server.PublicIPs != nil {
216+
rawServer["public_ip"] = server.PublicIPs[0].Address.String()
220217
rawServer["public_ips"] = flattenServerPublicIPs(server.Zone, server.PublicIPs)
221218
}
222219

templates/resources/instance_server.md.tmpl

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

0 commit comments

Comments
 (0)