Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize edge deployment backend updates via mutex #213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading