provider/scaleway: work around API concurrency issue (#12707)

when creating IPs concurrently the Scaleway API starts to return 500 internal
server errors.

since the error goes away when limiting concurrent requests, as well as the fact that the golang net/http client is safe for concurrent use,
I'm assuming this is an API error on Scaleways side.

this CS introduces a workaround so terraform does not crash for now.
the work around needs to be removed once Scaleway fixes their API
This commit is contained in:
Raphael Randschau 2017-03-15 15:23:18 +01:00 committed by Paul Stack
parent 8ccd38013e
commit fcaafee06b
2 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package scaleway
import ( import (
"log" "log"
"sync"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/scaleway/scaleway-cli/pkg/api" "github.com/scaleway/scaleway-cli/pkg/api"
@ -30,8 +31,12 @@ func resourceScalewayIP() *schema.Resource {
} }
} }
var mu = sync.Mutex{}
func resourceScalewayIPCreate(d *schema.ResourceData, m interface{}) error { func resourceScalewayIPCreate(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway scaleway := m.(*Client).scaleway
mu.Lock()
defer mu.Unlock()
resp, err := scaleway.NewIP() resp, err := scaleway.NewIP()
if err != nil { if err != nil {
return err return err

View File

@ -8,6 +8,23 @@ import (
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccScalewayIP_Count(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckScalewayIPDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckScalewayIPConfig_Count,
Check: resource.ComposeTestCheckFunc(
testAccCheckScalewayIPExists("scaleway_ip.base.0"),
testAccCheckScalewayIPExists("scaleway_ip.base.1"),
),
},
},
})
}
func TestAccScalewayIP_Basic(t *testing.T) { func TestAccScalewayIP_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -129,6 +146,12 @@ resource "scaleway_ip" "base" {
} }
` `
var testAccCheckScalewayIPConfig_Count = `
resource "scaleway_ip" "base" {
count = 2
}
`
var testAccCheckScalewayIPAttachConfig = fmt.Sprintf(` var testAccCheckScalewayIPAttachConfig = fmt.Sprintf(`
resource "scaleway_server" "base" { resource "scaleway_server" "base" {
name = "test" name = "test"