【问题标题】:How to force a specific pattern for a variable value如何为变量值强制使用特定模式
【发布时间】:2020-07-03 08:03:15
【问题描述】:

我是 Terraform 的新手,我想知道如何使用它过滤标签,我的意思是从名称标签“电子邮件”中,我们必须要求用户在值标签输入中输入特定格式“xxx@example.com” .

【问题讨论】:

    标签: azure terraform terraform-provider-azure


    【解决方案1】:

    我认为 terraform 最近的实验性功能之一应该可以帮助您:

    variable "email" {
      type = string
    
      validation {
        condition = can(regex("^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$", var.email))
        error_message = "ERROR: Not a valid email"
      }
    }
    

    https://www.terraform.io/docs/configuration/functions/can.html

    这个功能需要这个:

    terraform {
      experiments = [variable_validation]
    }
    

    https://www.terraform.io/docs/configuration/variables.html#custom-validation-rules

    【讨论】:

      猜你喜欢
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 2014-07-31
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 2014-04-29
      相关资源
      最近更新 更多