1

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."
  } 
}
2
  • What do you want to achieve? Do you have examples of valid input and invalid ones? Commented Mar 16, 2021 at 3:57
  • valid input is between [0-12] if any value more than 12 is not acceptable want to achieve same thing as posted in above snippet, but with loop or something else. Commented Mar 16, 2021 at 4:03

1 Answer 1

1

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."
  } 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.