provider/scaleway: use building DetachIP func
This commit is contained in:
parent
85b982f26d
commit
a5d105da36
|
@ -1,9 +1,7 @@
|
|||
package scaleway
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/scaleway/scaleway-cli/pkg/api"
|
||||
|
@ -19,33 +17,6 @@ func String(val string) *string {
|
|||
return &val
|
||||
}
|
||||
|
||||
// DetachIP detaches an IP from a server
|
||||
func DetachIP(s *api.ScalewayAPI, ipID string) error {
|
||||
var update struct {
|
||||
Address string `json:"address"`
|
||||
ID string `json:"id"`
|
||||
Organization string `json:"organization"`
|
||||
}
|
||||
|
||||
ip, err := s.GetIP(ipID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
update.Address = ip.IP.Address
|
||||
update.ID = ip.IP.ID
|
||||
update.Organization = ip.IP.Organization
|
||||
|
||||
resp, err := s.PutResponse(api.ComputeAPI, fmt.Sprintf("ips/%s", ipID), update)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return err
|
||||
}
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// NOTE copied from github.com/scaleway/scaleway-cli/pkg/api/helpers.go
|
||||
// the helpers.go file pulls in quite a lot dependencies, and they're just convenience wrappers anyway
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ func resourceScalewayIPUpdate(d *schema.ResourceData, m interface{}) error {
|
|||
}
|
||||
} else {
|
||||
log.Printf("[DEBUG] Detaching IP %q\n", d.Id())
|
||||
return DetachIP(scaleway, d.Id())
|
||||
return scaleway.DetachIP(d.Id())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue