terraform-provider-mssql
terraform-provider-mssql copied to clipboard
Random failures when creating a user soon after the database has been created
I'm trying to create contained database users right after a database has been created using the azurerm_mssql_database
resourrce. However the mssql_user
create request fails for various reasons:
Error: unable to read user [my-database-name].[my-user]: login error: mssql: Login failed for user 'admin'.
Another error:
Error: unable to create user [my-database-name].[my-user]: SQL Server had internal error
When retrying a moment later by planning and applying only the failed user terraform succeeds.
There seems to be some sort of timing issue where the database has been created but is not ready to receive any commands yet. I've seen this problem before when provisioning a local containerized instance of SQL Server and trying to connect and execute scripts right after using sqlcmd
. A delay in-between seems to sort it out, but it's of course a hacky, brittle solution.