From cd3b5bef09f99447a8580e7a63b4412d97aa1b30 Mon Sep 17 00:00:00 2001 From: Jon Nangle Date: Wed, 27 Mar 2024 16:20:00 +0000 Subject: [PATCH] Serialize edge deployment backend updates via mutex (#213) --- provider/lib.go | 2 ++ provider/provider.go | 4 ++++ provider/resource_edge_deployment_service_update_backend.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/provider/lib.go b/provider/lib.go index be30812..36b2f6f 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)) }