@@ -192,12 +192,6 @@ func ResourceServer() *schema.Resource {
192192 Optional : true ,
193193 Description : "The additional volumes attached to the server" ,
194194 },
195- "private_ip" : {
196- Type : schema .TypeString ,
197- Computed : true ,
198- Description : "The Scaleway internal IP address of the server" ,
199- Deprecated : "Use ipam_ip datasource instead to fetch your server's IP in your private network." ,
200- },
201195 "ip_id" : {
202196 Type : schema .TypeString ,
203197 Optional : true ,
@@ -658,10 +652,6 @@ func ResourceInstanceServerRead(ctx context.Context, d *schema.ResourceData, m a
658652 _ = d .Set ("placement_group_policy_respected" , server .PlacementGroup .PolicyRespected )
659653 }
660654
661- if server .PrivateIP != nil {
662- _ = d .Set ("private_ip" , types .FlattenStringPtr (server .PrivateIP ))
663- }
664-
665655 if ipID , hasIPID := d .GetOk ("ip_id" ); hasIPID {
666656 publicIP := FindIPInList (ipID .(string ), server .PublicIPs )
667657 if publicIP != nil && ! publicIP .Dynamic {
@@ -956,54 +946,21 @@ func ResourceInstanceServerUpdate(ctx context.Context, d *schema.ResourceData, m
956946 // Update reserved IP
957947 ////
958948 if d .HasChange ("ip_id" ) && ! instanceIPHasMigrated (d ) {
959- server , err := waitForServer (ctx , api .API , zone , id , d .Timeout (schema .TimeoutUpdate ))
960- if err != nil {
961- return diag .FromErr (err )
962- }
963-
964949 ipID := zonal .ExpandID (d .Get ("ip_id" )).ID
965- // If an IP is already attached, and it's not a dynamic IP we detach it.
966- publicIP := FindIPInList (ipID , server .PublicIPs )
967- if publicIP != nil && ! publicIP .Dynamic {
968- _ , err = api .UpdateIP (& instanceSDK.UpdateIPRequest {
969- Zone : zone ,
970- IP : publicIP .ID ,
971- Server : & instanceSDK.NullableStringValue {Null : true },
972- })
973- if err != nil {
974- return diag .FromErr (err )
975- }
976- // we wait to ensure to not detach the new ip.
977- _ , err := waitForServer (ctx , api .API , zone , id , d .Timeout (schema .TimeoutUpdate ))
978- if err != nil {
979- return diag .FromErr (err )
980- }
981- }
982- // If a new IP is provided, we attach it to the server
983- if ipID != "" {
984- _ , err := waitForServer (ctx , api .API , zone , id , d .Timeout (schema .TimeoutUpdate ))
985- if err != nil {
986- return diag .FromErr (err )
987- }
988-
989- _ , err = api .UpdateIP (& instanceSDK.UpdateIPRequest {
990- Zone : zone ,
991- IP : ipID ,
992- Server : & instanceSDK.NullableStringValue {Value : id },
993- }, scw .WithContext (ctx ))
994- if err != nil {
995- return diag .FromErr (err )
996- }
997-
998- _ , 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" )
999956 if err != nil {
1000957 return diag .FromErr (err )
1001958 }
1002959 }
1003960 }
1004961
1005962 if d .HasChange ("ip_ids" ) {
1006- err := ResourceInstanceServerUpdateIPs (ctx , d , api .API , zone , id )
963+ err := ResourceInstanceServerUpdateIPs (ctx , d , api .API , zone , id , "ip_ids" )
1007964 if err != nil {
1008965 return diag .FromErr (err )
1009966 }
@@ -1418,13 +1375,20 @@ func ResourceInstanceServerMigrate(ctx context.Context, d *schema.ResourceData,
14181375 return nil
14191376}
14201377
1421- func ResourceInstanceServerUpdateIPs (ctx context.Context , d * schema.ResourceData , instanceAPI * instanceSDK.API , zone scw.Zone , id string ) error {
1378+ func ResourceInstanceServerUpdateIPs (ctx context.Context , d * schema.ResourceData , instanceAPI * instanceSDK.API , zone scw.Zone , id string , attribute string ) error {
14221379 server , err := waitForServer (ctx , instanceAPI , zone , id , d .Timeout (schema .TimeoutUpdate ))
14231380 if err != nil {
14241381 return err
14251382 }
14261383
1427- schemaIPs := d .Get ("ip_ids" ).([]any )
1384+ var schemaIPs []any
1385+ switch attribute {
1386+ case "ip_id" :
1387+ schemaIP := d .Get (attribute ).(string )
1388+ schemaIPs = append (schemaIPs , schemaIP )
1389+ case "ip_ids" :
1390+ schemaIPs = d .Get (attribute ).([]any )
1391+ }
14281392 requestedIPs := make (map [string ]bool , len (schemaIPs ))
14291393
14301394 // Gather request IPs in a map
0 commit comments