简体   繁体   English

Terraform 变量验证

[英]Terraform variable validation

How to use loop or something else to make it efficient way not using regex.如何使用循环或其他方式使其成为不使用正则表达式的有效方式。

variable "instance_auto_renew_period" {
  description = "Instance auto-renewal period (in months). Set it to 0 if you want to disable auto renew of DB instance."
  default     = 0
  type        = string
  validation {
    condition     = contains(["0", 1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"], var.instance_auto_renew_period)
    error_message = "Must be an valid instance_auto_renew_period."
  } 
}

I think the easiest way to achieve that is as follows:我认为实现这一目标的最简单方法如下:

variable "instance_auto_renew_period" {
  description = "Instance auto-renewal period (in months). Set it to 0 if you want to disable auto renew of DB instance."
  default     = 0
  type        = number
  validation {
    condition     = var.instance_auto_renew_period <= 12 && var.instance_auto_renew_period >= 0
    error_message = "Must be an valid instance_auto_renew_period."
  } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM