@@ -118,29 +118,44 @@ func (s *Stackit) Delete(ctx context.Context, projectId, machineName string) err
118118
119119 gotError := false
120120
121- if len (* server .Nics ) == 0 {
121+ err = s .client .DeleteServer (ctx , projectId , * server .Id ).Execute ()
122+ if err != nil {
123+ log .Default .Errorf ("failed to delete server" )
124+ }
125+ _ , err = wait .DeleteServerWaitHandler (ctx , s .client , projectId , * server .Id ).WaitWithContext (ctx )
126+ if err != nil {
127+ log .Default .Errorf ("error while waiting for server deletion" )
128+ }
129+
130+ nics := * server .Nics
131+ if len (nics ) == 0 {
122132 log .Default .Errorf ("no networks found for server" )
123133 gotError = true
124134 } else {
125- nics := * server .Nics
135+ publicIPAddress := nics [0 ].PublicIp
136+ if publicIPAddress != nil {
137+ publicIP , err := s .getPublicIPByIPAddress (ctx , projectId , * publicIPAddress )
138+ if err != nil {
139+ log .Default .Errorf ("failed to get public IP" )
140+ gotError = true
141+ }
142+
143+ err = s .client .DeletePublicIP (ctx , projectId , * publicIP .Id ).Execute ()
144+ if err != nil {
145+ log .Default .Errorf ("failed to delete public IP" )
146+ gotError = true
147+ }
148+ }
149+
126150 networkId := nics [0 ].NetworkId
127151 err = s .client .DeleteNetwork (ctx , projectId , * networkId ).Execute ()
128152 if err != nil {
129153 log .Default .Errorf ("failed to delete network" )
130154 gotError = true
131155 }
132-
133- publicIPAddress := nics [0 ].PublicIp
134- publicIP , err := s .getPublicIPByIPAddress (ctx , projectId , * publicIPAddress )
156+ _ , err = wait .DeleteNetworkWaitHandler (ctx , s .client , projectId , * networkId ).WaitWithContext (ctx )
135157 if err != nil {
136- log .Default .Errorf ("failed to get public IP" )
137- gotError = true
138- }
139-
140- err = s .client .DeletePublicIP (ctx , projectId , * publicIP .Id ).Execute ()
141- if err != nil {
142- log .Default .Errorf ("failed to delete public IP" )
143- gotError = true
158+ log .Default .Errorf ("error while waiting for network deletion" )
144159 }
145160
146161 for _ , id := range * nics [0 ].SecurityGroups {
0 commit comments