variable "account" {
  type        = string
  description = "Snowflake account name"
  default     = "DELPHI"
}

variable "region" {
  type        = string
  default     = "us-east-1"
  description = "Snowflake account region"
}

variable "revert_ownership_to" {
  type        = string
  default     = "USERADMIN"
  description = "Role to which will be reverted ownership from a custom ones during removal"
}

variable "roles" {
  description = "List of objects containing role details"
  type = list(object({
    name                      = string
    granted_account_roles     = optional(list(string))
    granted_database_roles    = optional(list(string))
    account_level_grants      = optional(set(string))
    granted_application_roles = optional(set(string))
    grant_to_sysadmin         = optional(bool, true)
    comment                   = optional(string, "Managed by Terraform")
    owner                     = optional(string, "USERADMIN")
  }))

  validation {
    condition = alltrue([
      for role in var.roles : can(regex("[[:upper:]]", role.name))
    ])
    error_message = "Error: Role name must be uppercase."
  }
}
