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

`default_scema` is not set for identities from `EXTERNAL PROVIDER` for Azure SQL Database Users. #63

Open dhizzlewizzork opened 1 year ago

dhizzlewizzork commented 1 year ago

I believe this could be updated here: https://github.com/betr-io/terraform-provider-mssql/blob/master/sql/user.go#L113

When the default_schema is not set, we have found that identities (such as managed identities that are members of Azure Entra ID groups) run into issues when running trying to run database migrations that involve setting up schemas, tables, etc.

Typically an error is thrown similar to the following:

Error occurred during DB Migration: "The specified schema name \"<Object ID>@<Directory/Tenant ID>\" either does not exist or you do not have permission to use it."

This gets fixed by running:

ALTER USER [<Azure Entra ID Group Name>] WITH DEFAULT_SCHEMA=[dbo]

Which might be accounted for by specifying the default_schema in the CreateUser function.