Skip to content

Commit 276ff83

Browse files
authored
Merge pull request hashicorp#9312 from nicolai86/chore/upgrade-scaleway-api
provider/scaleway: SDK upgrade
2 parents f1503d3 + 5e107cd commit 276ff83

11 files changed

Lines changed: 456 additions & 265 deletions

File tree

builtin/providers/scaleway/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type Config struct {
1515
Organization string
1616
APIKey string
17+
Region string
1718
}
1819

1920
// Client contains scaleway api clients
@@ -27,6 +28,7 @@ func (c *Config) Client() (*Client, error) {
2728
c.Organization,
2829
c.APIKey,
2930
scwversion.UserAgent(),
31+
c.Region,
3032
func(s *api.ScalewayAPI) {
3133
s.Logger = newTerraformLogger()
3234
},

builtin/providers/scaleway/helpers.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package scaleway
22

33
import (
4-
"fmt"
54
"log"
6-
"net/http"
75
"time"
86

97
"github.com/scaleway/scaleway-cli/pkg/api"
@@ -19,33 +17,6 @@ func String(val string) *string {
1917
return &val
2018
}
2119

22-
// DetachIP detaches an IP from a server
23-
func DetachIP(s *api.ScalewayAPI, ipID string) error {
24-
var update struct {
25-
Address string `json:"address"`
26-
ID string `json:"id"`
27-
Organization string `json:"organization"`
28-
}
29-
30-
ip, err := s.GetIP(ipID)
31-
if err != nil {
32-
return err
33-
}
34-
update.Address = ip.IP.Address
35-
update.ID = ip.IP.ID
36-
update.Organization = ip.IP.Organization
37-
38-
resp, err := s.PutResponse(api.ComputeAPI, fmt.Sprintf("ips/%s", ipID), update)
39-
if err != nil {
40-
return err
41-
}
42-
if resp.StatusCode != http.StatusOK {
43-
return err
44-
}
45-
resp.Body.Close()
46-
return nil
47-
}
48-
4920
// NOTE copied from github.com/scaleway/scaleway-cli/pkg/api/helpers.go
5021
// the helpers.go file pulls in quite a lot dependencies, and they're just convenience wrappers anyway
5122

builtin/providers/scaleway/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ func Provider() terraform.ResourceProvider {
2121
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_ORGANIZATION", nil),
2222
Description: "The Organization ID for Scaleway API operations.",
2323
},
24+
"region": &schema.Schema{
25+
Type: schema.TypeString,
26+
Optional: true,
27+
DefaultFunc: schema.EnvDefaultFunc("SCALEWAY_REGION", "par1"),
28+
Description: "The Scaleway API region to use.",
29+
},
2430
},
2531

2632
ResourcesMap: map[string]*schema.Resource{
@@ -40,6 +46,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
4046
config := Config{
4147
Organization: d.Get("organization").(string),
4248
APIKey: d.Get("access_key").(string),
49+
Region: d.Get("region").(string),
4350
}
4451

4552
return config.Client()

builtin/providers/scaleway/resource_scaleway_ip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func resourceScalewayIPUpdate(d *schema.ResourceData, m interface{}) error {
7070
}
7171
} else {
7272
log.Printf("[DEBUG] Detaching IP %q\n", d.Id())
73-
return DetachIP(scaleway, d.Id())
73+
return scaleway.DetachIP(d.Id())
7474
}
7575
}
7676

0 commit comments

Comments
 (0)