diff --git a/provider/lib.go b/provider/lib.go index b8b64ff..45545ef 100644 --- a/provider/lib.go +++ b/provider/lib.go @@ -5,6 +5,7 @@ import ( "sort" "strconv" "strings" + "sync" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/signalsciences/go-sigsci" @@ -24,6 +25,7 @@ func suppressRequestLoggingDefaultDiffs(k, old, new string, d *schema.ResourceDa type providerMetadata struct { Corp string Client sigsci.Client + Mutex *sync.Mutex } func flattenStringArray(entries []string) []interface{} { diff --git a/provider/provider.go b/provider/provider.go index 40b95e3..315ba67 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -4,6 +4,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/signalsciences/go-sigsci" + "sync" ) // Provider is the Signalsciences terraform provider, returns a terraform.ResourceProvider @@ -89,6 +90,8 @@ func Provider() terraform.ResourceProvider { return provider } +var ProviderMutex sync.Mutex + func providerConfigure() schema.ConfigureFunc { return func(d *schema.ResourceData) (interface{}, error) { config := Config{ @@ -106,6 +109,7 @@ func providerConfigure() schema.ConfigureFunc { metadata := providerMetadata{ Corp: d.Get("corp").(string), Client: client.(sigsci.Client), + Mutex: &ProviderMutex, } validate := d.Get("validate").(bool) diff --git a/provider/resource_edge_deployment_service_update_backend.go b/provider/resource_edge_deployment_service_update_backend.go index 4effc1f..bc5ff42 100644 --- a/provider/resource_edge_deployment_service_update_backend.go +++ b/provider/resource_edge_deployment_service_update_backend.go @@ -37,6 +37,9 @@ func updateEdgeDeploymentServiceBackend(d *schema.ResourceData, m interface{}) e d.SetId(d.Get("fastly_sid").(string)) + ProviderMutex.Lock() + defer ProviderMutex.Unlock() + return pm.Client.UpdateEdgeDeploymentBackends(pm.Corp, d.Get("site_short_name").(string), d.Get("fastly_sid").(string)) }