@@ -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
0 commit comments