Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/server: validate instance type availability #69

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions scaleway/resource_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ func resourceScalewayServerCreate(d *schema.ResourceData, m interface{}) error {
req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool))
req.CommercialType = d.Get("type").(string)

availabilities, err := scaleway.GetServerAvailabilities()
if err != nil {
log.Printf("[DEBUG] Unable to fetch server availability; won't validate availability: %q\n", err.Error())
} else {
typeAvailability, ok := availabilities[req.CommercialType]
if !ok {
// this will most likely happen for new instance types
log.Printf("[DEBUG] no server availability for type %q. Ignoring\n", req.CommercialType)
}
if typeAvailability.Availability == api.InstanceTypeShortage {
return fmt.Errorf("InstanceType %s is currently out of stock", req.CommercialType)
}
}

if bootscript, ok := d.GetOk("bootscript"); ok {
req.Bootscript = String(bootscript.(string))
}
Expand Down
14 changes: 13 additions & 1 deletion vendor/github.com/nicolai86/scaleway-sdk/availability.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@
"revisionTime": "2016-10-03T17:45:16Z"
},
{
"checksumSHA1": "5PC3eHJZwTMQyGJltpcIJp/aCNw=",
"checksumSHA1": "ucJEyEBIAPbSsctcjxHTqN/1aoo=",
"path": "github.com/nicolai86/scaleway-sdk",
"revision": "4871b0a66c85ce1a78bb5d8a62714ed1a5669650",
"revisionTime": "2018-05-12T06:04:43Z"
"revision": "a7b61129ca818b3a2d1ebb3d276ed82b5b7eabfe",
"revisionTime": "2018-06-24T01:24:03Z"
},
{
"checksumSHA1": "u5s2PZ7fzCOqQX7bVPf9IJ+qNLQ=",
Expand Down