terraform-provider-mssql
terraform-provider-mssql copied to clipboard
mssql_schema_permission bug
When mssql_schema_permission depends on the user (which should be created before), I get an error that schema and database must belong to the same database.
If I create a plan with mssql_sql_user only, apply it, and then create the next one (which wants to create mssql_sql_user only), there is no error.
Configuration:
data "mssql_schema" "schema" {
name = "schDataLake"
database_id = data.mssql_database.database.id
lifecycle {
postcondition {
condition = self.id != null
error_message = "Schema must exist"
}
}
}
resource "mssql_sql_user" "user" {
name = local.dl_user
database_id = data.mssql_database.database.id
login_id = data.mssql_sql_login.login.id
}
resource "mssql_schema_permission" "schema_permission" {
schema_id = data.mssql_schema.schema.id
principal_id = mssql_sql_user.user.id
permission = "SELECT"
depends_on = [
mssql_sql_user.user
]
}
Output:
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform planned the following actions, but then encountered a problem:
# mssql_sql_user.user will be created
+ resource "mssql_sql_user" "user" {
+ database_id = "56"
+ id = (known after apply)
+ login_id = "0x010600000000006400000000000000008875E4B7A6B3064D8F72C34AC9869B0A"
+ name = "bg_test"
}
Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Error: Schema and Principal must belong to the same DB
│
│ with mssql_schema_permission.schema_permission,
│ on main.tf line 75, in resource "mssql_schema_permission" "schema_permission":
│ 75: resource "mssql_schema_permission" "schema_permission" {
│
│ schema_id points to DB with ID 56 while principal_id points to DB with ID 0
╵