PGSSoft / terraform-provider-mssql

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

using count to create multiple dbs does not work #95

Closed Krad-dono closed 1 year ago

Krad-dono commented 1 year ago

Hi, have a problem trying to create multiple db's using count. My code is:

resource "mssql_database" "rds_db" {
  count     = var.setup_databases ? length(var.db_names) : 0
  name      = var.db_names[count.index]
  collation = var.collation_name
}

Plan is successful and only when I hit apply I get this:

module.rds.mssql_database.rds_db[1]: Creating... module.rds.mssql_database.rds_db[2]: Creating... module.rds.mssql_database.rds_db[0]: Creating... module.rds.mssql_database.rds_db[1]: Creation complete after 7s [id=6] ╷ │ Error: Could not execute SQL │ │ with module.rds.mssql_database.rds_db[0], │ on ....\modules\rds\sql-setup.tf line 11, in resource "mssql_database" "rds_db": │ 11: resource "mssql_database" "rds_db" { │ │ mssql: The transaction ended in the trigger. The batch has been aborted. ╵ ╷ │ Error: Could not execute SQL │ │ with module.rds.mssql_database.rds_db[2], │ on ....\modules\rds\sql-setup.tf line 11, in resource "mssql_database" "rds_db": │ 11: resource "mssql_database" "rds_db" { │ │ mssql: The transaction ended in the trigger. The batch has been aborted.

So in general it creates only one DB from list and others fail. I can rerun apply again, then again it will only create another missing DB and other remaining will fail. The same when for_each is used. Any idea what is going on here?

tkielar-pgs commented 1 year ago

Duplicate of #91