PGSSoft / terraform-provider-mssql

MS SQL Terraform provider
MIT License
17 stars 9 forks source link

mssql_schema_permission bug #132

Open leonfibal opened 11 months ago

leonfibal commented 11 months ago

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
╵
Flasheh commented 10 months ago

Also hitting his issue at the moment. Would you have time to look at this @tkielar-pgs? Since this really breaks our entire flow.

l33tCod-er commented 7 months ago

Any update on this? Hit the same....