Skip to content

Commit

Permalink
Serialize edge deployment backend updates via mutex (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnangle authored Mar 27, 2024
1 parent 20ccedc commit cd3b5be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"
"strconv"
"strings"
"sync"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/signalsciences/go-sigsci"
Expand All @@ -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{} {
Expand Down
4 changes: 4 additions & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions provider/resource_edge_deployment_service_update_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}
Expand Down

0 comments on commit cd3b5be

Please sign in to comment.