betr-io / terraform-provider-mssql

Terraform provider for Microsoft SQL Server
https://registry.terraform.io/providers/betr-io/mssql/latest
MIT License
35 stars 28 forks source link

Fix concurrency issue on user create/update #52

Closed beandrad closed 1 year ago

beandrad commented 1 year ago

When creating or updating a mssql user in servers with compatibility level below 130, the string_split function needs to be created.

At the moment, this is causing issues when trying to create/update multiple users, as each of those requests tries to create the same function.

This change introduces a lock on application resource in exclusive mode so that only one of the calls attempts to create the function.

Fixes #31

alxy commented 1 year ago

@beandrad Does it maybe make sense to add a simple acceptance test for this that would add few users in parallel. As these tests run rather fast against local infrastructure, I think that would be valuable?

beandrad commented 1 year ago

@beandrad Does it maybe make sense to add a simple acceptance test for this that would add few users in parallel. As these tests run rather fast against local infrastructure, I think that would be valuable?

Thanks for the comment. I added a test that creates multiple users at once; I run it after setting compatibility level in my local db to 120 and removing the "string_split" function. Of course, I also tested these changes with a Terraform script that creates multiple users , in this case, in Azure MSSQL.