I am trying to create user credentials in Azure SQL Server for each DB with their own set of roles added to them but I am having difficulty in getting the proper result from random password resources any insights would be helpful
Here is my code
variable "db_details" {
description = "Details of certs to be created"
type = list(object({
db_name = string
roles = list(string)
}))
}
## Random Password for SQL db's
resource "random_password" "db_passwords" {
for_each = { for db in var.db_details : db.db_name => db }
length = 32
special = false
}
resource "mssql_user" "db_users" {
server {
host = "mysqlserverr"
port = "1433"
login {
username = local.sql_server_username
password = data.azurerm_key_vault_secret.sql_server_password.value
}
}
for_each = { for db in var.db_details : db.db_name => db }
database = join("-", [
local.resource_name_prefix,
each.value.db
])
username = join("-", [
"svc",
each.value.db,
"user"
])
password = random_password.db_passwords[each.value.db].result
roles = each.value.roles
}
What I want to achieve is to get a result of each db index key at random.password resource passed to the corresponding db in password
Here is the error log
│ Error: Unsupported attribute
│
│ on sql.tf line 130, in resource "mssql_user" "db_users":
│ 130: each.value.db
│ ├────────────────
│ │ each.value is object with 2 attributes
│
│ This object does not have an attribute named "db".