Skip to content

Commit

Permalink
provider/scaleway: work around API concurrency issue (#12707)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolai86 authored and stack72 committed Mar 15, 2017
1 parent 8ccd380 commit fcaafee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/providers/scaleway/resource_scaleway_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scaleway

import (
"log"
"sync"

"github.com/hashicorp/terraform/helper/schema"
"github.com/scaleway/scaleway-cli/pkg/api"
Expand Down Expand Up @@ -30,8 +31,12 @@ func resourceScalewayIP() *schema.Resource {
}
}

var mu = sync.Mutex{}

func resourceScalewayIPCreate(d *schema.ResourceData, m interface{}) error {
scaleway := m.(*Client).scaleway
mu.Lock()
defer mu.Unlock()
resp, err := scaleway.NewIP()
if err != nil {
return err
Expand Down
23 changes: 23 additions & 0 deletions builtin/providers/scaleway/resource_scaleway_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import (
"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) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -129,6 +146,12 @@ resource "scaleway_ip" "base" {
}
`

var testAccCheckScalewayIPConfig_Count = `
resource "scaleway_ip" "base" {
count = 2
}
`

var testAccCheckScalewayIPAttachConfig = fmt.Sprintf(`
resource "scaleway_server" "base" {
name = "test"
Expand Down

0 comments on commit fcaafee

Please sign in to comment.