From 22a578b9c72d69092d5c1a49406d0bb48a5472ef Mon Sep 17 00:00:00 2001 From: Dmitrii Trunin Date: Tue, 1 Oct 2024 10:52:06 +0200 Subject: [PATCH] fix: pq: duplicate key violates unique constraint pg_defacl_name_index (possibly caused by concurrent transaction conflict) --- redshift/resource_redshift_default_privileges.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/redshift/resource_redshift_default_privileges.go b/redshift/resource_redshift_default_privileges.go index af19f24..66a4f98 100644 --- a/redshift/resource_redshift_default_privileges.go +++ b/redshift/resource_redshift_default_privileges.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "strings" + "sync" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -30,6 +31,8 @@ var defaultPrivilegesObjectTypesCodes = map[string]string{ "table": "r", } +var defaultPrivilegesMutex sync.Mutex + func redshiftDefaultPrivileges() *schema.Resource { return &schema.Resource{ Description: `Defines the default set of access privileges to be applied to objects that are created in the future by the specified user. By default, users can change only their own default access privileges. Only a superuser can specify default privileges for other users.`, @@ -112,6 +115,9 @@ func resourceRedshiftDefaultPrivilegesDelete(db *DBConnection, d *schema.Resourc } func resourceRedshiftDefaultPrivilegesCreate(db *DBConnection, d *schema.ResourceData) error { + defaultPrivilegesMutex.Lock() + defer defaultPrivilegesMutex.Unlock() + privilegesSet := d.Get(defaultPrivilegesPrivilegesAttr).(*schema.Set) objectType := d.Get(defaultPrivilegesObjectTypeAttr).(string)