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

terraform apply always wants to do in place update #46

Closed DaleyKD closed 1 year ago

DaleyKD commented 2 years ago

I did an import: terraform import 'module.sql_db.mssql_user.msi[\"dev-group\"]' 'mssql://mysqlserver.database.windows.net/mydb/dev-group' and it imported the following roles: "db_ddladmin", "db_datareader", "db_datawriter", in that order.

Now, whenever I do terraform apply, it wants to modify the resource, because the following is my resource block:

resource "mssql_user" "msi" {
  for_each = var.managed_identity_groups

  server {
    host = data.azurerm_mssql_server.main.fully_qualified_domain_name
    login {
      username = data.azurerm_mssql_server.main.administrator_login
      password = data.azurerm_key_vault_secret.sqladminsecret.value
    }
  }

  database  = azurerm_mssql_database.db1.name
  username  = each.key
  object_id = each.value
  roles = [
    "db_datareader",
    "db_datawriter",
    "db_ddladmin"
  ]
}

Just because the roles array is in a different order. Even if I tell it to go ahead and apply, the next time I try, it still wants to update the resource.

jnsvd commented 1 year ago

I have the same issue (with the exact same list of roles). Best workaround is to synchronize the code with the order in the actual infrastructure.

magne commented 1 year ago

Fixed by #53.