From fcaafee06b188cbe0265c16c2d9b58df02c25e7a Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Wed, 15 Mar 2017 15:23:18 +0100 Subject: [PATCH] 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 --- .../scaleway/resource_scaleway_ip.go | 5 ++++ .../scaleway/resource_scaleway_ip_test.go | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/builtin/providers/scaleway/resource_scaleway_ip.go b/builtin/providers/scaleway/resource_scaleway_ip.go index 96572e62b..27cb6fb47 100644 --- a/builtin/providers/scaleway/resource_scaleway_ip.go +++ b/builtin/providers/scaleway/resource_scaleway_ip.go @@ -2,6 +2,7 @@ package scaleway import ( "log" + "sync" "github.com/hashicorp/terraform/helper/schema" "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 { scaleway := m.(*Client).scaleway + mu.Lock() + defer mu.Unlock() resp, err := scaleway.NewIP() if err != nil { return err diff --git a/builtin/providers/scaleway/resource_scaleway_ip_test.go b/builtin/providers/scaleway/resource_scaleway_ip_test.go index f32cae1f5..f3381cedf 100644 --- a/builtin/providers/scaleway/resource_scaleway_ip_test.go +++ b/builtin/providers/scaleway/resource_scaleway_ip_test.go @@ -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) }, @@ -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"