Skip to content

Commit

Permalink
Merge branch 'master' into upstream-v5.49.0
Browse files Browse the repository at this point in the history
  • Loading branch information
flostadler committed May 14, 2024
2 parents dd04274 + e354011 commit 54f1756
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions patches/0052-non-idempotent-sns-topic-creation.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@ index b9a8e0b2f7..a1f83415f1 100644
}
}

+func constructTopicArn(client *sns.Client, account, region, snsTopicName string) string {
+ return fmt.Sprintf("arn:aws:sns:%s:%s:%s", region, account, snsTopicName)
+func constructTopicArn(client *sns.Client, account, region, partition, snsTopicName string) string {
+ return fmt.Sprintf("arn:%s:sns:%s:%s:%s", partition, region, account, snsTopicName)
+}
+
+var snsGlobalMutex sync.Map
+
func resourceTopicCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SNSClient(ctx)
@@ -284,6 +291,27 @@ func resourceTopicCreate(ctx context.Context, d *schema.ResourceData, meta inter
@@ -284,6 +291,28 @@ func resourceTopicCreate(ctx context.Context, d *schema.ResourceData, meta inter
delete(attributes, topicAttributeNameFIFOTopic)
}

+ // create a lock based on the topic ARN. We really want to make sure
+ // that we prevent a race condition where two resources are created with
+ // the same name.
+ topicArn := constructTopicArn(conn, meta.(*conns.AWSClient).AccountID, meta.(*conns.AWSClient).Region, name)
+ awsClient := meta.(*conns.AWSClient)
+ topicArn := constructTopicArn(conn, awsClient.AccountID, awsClient.Region, awsClient.Partition, name)
+ localMutex := &sync.Mutex{}
+ if val, ok := snsGlobalMutex.LoadOrStore(topicArn, localMutex); ok {
+ localMutex = val.(*sync.Mutex)
Expand Down

0 comments on commit 54f1756

Please sign in to comment.