Converting numeric to string(word) based on the condition

Hi i am trying to create the alert name based on the severity in the alert.In the input i have given numeric value for severity but i am trying to append equalent string(word) for that severity to the alert name

  • Critical = 0
  • Error= 1
  • Warning= 2
  • Informational = 3
  • Verbose = 4

module main.tf

I am getting alert name like keyvault - 0
i would like to get keyvault - critical

please guide me if anyone know a way to do that


resource "azurerm_monitor_metric_alert" "keyvault_alert" {

  for_each = var.keyvault_alert_rules
 name                = "${var.kv_name} - ${each.value.severity}"
  
  resource_group_name = var.resource_group_name
  description         = each.value.description
  scopes              = var.alert_scope
  severity            = each.value.severity
  frequency           = each.value.frequency
  `window_size         = each.value.windowsize`

# criteria block
  criteria {
    
    metric_namespace  = "Microsoft.KeyVault/vaults"
    threshold         = each.value.threshold
    metric_name       = each.value.metric_name
    aggregation       = each.value.aggregation
    operator          = each.value.operator

 # dimension block

    dynamic "dimension" {
      for_each = each.value.dimension != null ? each.value.dimension : []
      content {
          name     = dimension.value.dimensionname
          operator = dimension.value.dimensionoperator
          values   = dimension.value.dimensionvalues
      }
    }
        
  }

  action {
         action_group_id = var.action_group_id
       }

variable.tf


variable "action_group_id" {
    type = any
  description = "ID of the action group"
}


variable "resource_group_name" {
    type = string
  description = "name of the resource group"
}

/* in the variables i am passing warning as n input.is there any way i can append warning to alert name in the main.tf based on the severity value which is given down below*/

variable "kv_alert_rules" {
    type = map(object({  
     display_name = string
     # display_name = "(severity numeric equalent ex:warning)-(metric name)" 
     

     #------details for the alert criteria
     metric_name = string
     operator = string
     threshold = number 
     aggregation = string
        
    #------ dimension vaules----------
      dimension =  list(object({
        dimensionname = string
        dimensionoperator = string
        dimensionvalues = list(string)
      }))  
    #-----------------------------------
     severity = number
     frequency = string
     windowsize = string
     # window size must be gretar than Frequency values be PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D. Defaults to PT5M
     
     description = string
            
    }))

    description = "This variable for alert criteria for key vault"


            default = {
     "Alert_1" = {
      # display_name = "(severity numeric equalent ex:warning)-(generic word for metric name)"
    display_name = "warning-used capacity"
    severity = 2
    dimension = null
    metric_name = "SaturationShoebox"
    aggregation = "Average"
    frequency = "PT30M"
    description = "Alert fires When Used vault capacity is GreaterThan 85"
    windowsize = "PT1H"
    operator = "GreaterThan"
    threshold = 85
    }
  }
     }

variable "kv_name" {
  description = "key vault name "
  type = string 
}

module usage

module "keyvault" {
  source = "../testing/key-vault-alert"
   alert_scope = [data.azurerm_key_vault.examplekeyvault.id]
   action_group_id = module.action-group.AGidout
   resource_group_name = var.resource_group_name 
   kv_name = data.azurerm_key_vault.examplekeyvault.name
}